@@ -73,7 +73,10 @@ pub fn standalone_with_length_main(
7373 . transpose ( ) ?
7474 . flatten ( ) ;
7575
76- let format = OutputFormat :: from_standalone ( std:: env:: args_os ( ) ) ;
76+ //todo: deduplicate matches.get_flag
77+ let text = !matches. get_flag ( options:: BINARY ) ;
78+ let tag = matches. get_flag ( options:: TAG ) ;
79+ let format = OutputFormat :: from_standalone ( text, tag) ;
7780
7881 checksum_main ( algo, length, matches, format?)
7982}
@@ -82,8 +85,10 @@ pub fn standalone_with_length_main(
8285pub fn standalone_main ( algo : AlgoKind , cmd : Command , args : impl uucore:: Args ) -> UResult < ( ) > {
8386 let matches = uucore:: clap_localization:: handle_clap_result ( cmd, args) ?;
8487 let algo = Some ( algo) ;
85-
86- let format = OutputFormat :: from_standalone ( std:: env:: args_os ( ) ) ;
88+ //todo: deduplicate matches.get_flag
89+ let text = !matches. get_flag ( options:: BINARY ) ;
90+ let tag = matches. get_flag ( options:: TAG ) ;
91+ let format = OutputFormat :: from_standalone ( text, tag) ;
8792
8893 checksum_main ( algo, None , matches, format?)
8994}
@@ -154,24 +159,30 @@ pub fn checksum_main(
154159 let quiet = check_flag ( "quiet" ) ?;
155160 let strict = check_flag ( "strict" ) ?;
156161 let status = check_flag ( "status" ) ?;
162+ let text_flag = matches. get_flag ( options:: TEXT ) ;
163+ let binary_flag = matches. get_flag ( options:: BINARY ) ;
164+ let tag = matches. get_flag ( options:: TAG ) ;
157165
158166 // clap provides the default value -. So we unwrap() safety.
159167 let files = matches
160168 . get_many :: < OsString > ( options:: FILE )
161169 . unwrap ( )
162170 . map ( |s| s. as_os_str ( ) ) ;
163171
172+ if text_flag && tag {
173+ return Err ( ChecksumError :: TextAfterTag . into ( ) ) ;
174+ }
175+
164176 if check {
165177 // cksum does not support '--check'ing legacy algorithms
166178 if algo. is_some_and ( AlgoKind :: is_legacy) {
167179 return Err ( ChecksumError :: AlgorithmNotSupportedWithCheck . into ( ) ) ;
168180 }
169-
170- let text_flag = matches. get_flag ( options:: TEXT ) ;
171- let binary_flag = matches. get_flag ( options:: BINARY ) ;
172- let tag = matches. get_flag ( options:: TAG ) ;
173-
174- if tag || binary_flag || text_flag {
181+ // Maybe, we should just use clap
182+ if tag {
183+ return Err ( ChecksumError :: TagCheck . into ( ) ) ;
184+ }
185+ if binary_flag || text_flag {
175186 return Err ( ChecksumError :: BinaryTextConflict . into ( ) ) ;
176187 }
177188
0 commit comments