11use crate :: path_glob;
22use crate :: validation:: { validate_file_path, validate_output_path} ;
33use langcodec:: {
4- Codec , FormatType , KeyStyle , NormalizeOptions as EngineNormalizeOptions , normalize_codec,
4+ Codec , FormatType , KeyStyle , NormalizeOptions as EngineNormalizeOptions , ReadOptions ,
5+ normalize_codec,
56} ;
67use std:: collections:: HashSet ;
78use std:: path:: Path ;
@@ -15,6 +16,7 @@ pub struct NormalizeCliOptions {
1516 pub no_placeholders : bool ,
1617 pub key_style : String ,
1718 pub continue_on_error : bool ,
19+ pub strict : bool ,
1820}
1921
2022fn parse_key_style ( input : & str ) -> Result < KeyStyle , String > {
@@ -83,19 +85,20 @@ fn run_normalize_for_file(
8385 check : bool ,
8486 no_placeholders : bool ,
8587 key_style : & KeyStyle ,
88+ strict : bool ,
8689) -> Result < bool , String > {
8790 validate_file_path ( input) ?;
8891
8992 let mut codec = Codec :: new ( ) ;
9093 codec
91- . read_file_by_extension ( input, None )
94+ . read_file_by_extension_with_options ( input, & ReadOptions :: new ( ) . with_strict ( strict ) )
9295 . map_err ( |e| format ! ( "Failed to read input '{}': {}" , input, e) ) ?;
9396
9497 let report = normalize_codec (
9598 & mut codec,
9699 & EngineNormalizeOptions {
97100 normalize_placeholders : !no_placeholders,
98- key_style : key_style. clone ( ) ,
101+ key_style : * key_style,
99102 } ,
100103 )
101104 . map_err ( |e| e. to_string ( ) ) ?;
@@ -147,6 +150,10 @@ fn run_normalize_for_file(
147150pub fn run_normalize_command ( opts : NormalizeCliOptions ) -> Result < ( ) , String > {
148151 let expanded = path_glob:: expand_input_globs ( & opts. inputs )
149152 . map_err ( |e| format ! ( "Failed to expand input patterns: {}" , e) ) ?;
153+ let expanded: Vec < String > = expanded
154+ . into_iter ( )
155+ . filter ( |path| !has_glob_meta ( path) || Path :: new ( path) . is_file ( ) )
156+ . collect ( ) ;
150157 if expanded. is_empty ( ) {
151158 return Err ( "No input files matched the provided patterns" . to_string ( ) ) ;
152159 }
@@ -193,6 +200,7 @@ pub fn run_normalize_command(opts: NormalizeCliOptions) -> Result<(), String> {
193200 opts. check ,
194201 opts. no_placeholders ,
195202 & key_style,
203+ opts. strict ,
196204 ) {
197205 Ok ( changed) => {
198206 success_count += 1 ;
0 commit comments