@@ -74,7 +74,10 @@ pub fn standalone_with_length_main(
7474 . transpose ( ) ?
7575 . flatten ( ) ;
7676
77- let format = OutputFormat :: from_standalone ( std:: env:: args_os ( ) ) ;
77+ //todo: deduplicate matches.get_flag
78+ let text = !matches. get_flag ( options:: BINARY ) ;
79+ let tag = matches. get_flag ( options:: TAG ) ;
80+ let format = OutputFormat :: from_standalone ( text, tag) ;
7881
7982 checksum_main ( algo, length, matches, format?)
8083}
@@ -83,8 +86,10 @@ pub fn standalone_with_length_main(
8386pub fn standalone_main ( algo : AlgoKind , cmd : Command , args : impl uucore:: Args ) -> UResult < ( ) > {
8487 let matches = uucore:: clap_localization:: handle_clap_result ( cmd, args) ?;
8588 let algo = Some ( algo) ;
86-
87- let format = OutputFormat :: from_standalone ( std:: env:: args_os ( ) ) ;
89+ //todo: deduplicate matches.get_flag
90+ let text = !matches. get_flag ( options:: BINARY ) ;
91+ let tag = matches. get_flag ( options:: TAG ) ;
92+ let format = OutputFormat :: from_standalone ( text, tag) ;
8893
8994 checksum_main ( algo, None , matches, format?)
9095}
@@ -155,24 +160,30 @@ pub fn checksum_main(
155160 let quiet = check_flag ( "quiet" ) ?;
156161 let strict = check_flag ( "strict" ) ?;
157162 let status = check_flag ( "status" ) ?;
163+ let text_flag = matches. get_flag ( options:: TEXT ) ;
164+ let binary_flag = matches. get_flag ( options:: BINARY ) ;
165+ let tag = matches. get_flag ( options:: TAG ) ;
158166
159167 // clap provides the default value -. So we unwrap() safety.
160168 let files = matches
161169 . get_many :: < OsString > ( options:: FILE )
162170 . unwrap ( )
163171 . map ( Borrow :: borrow) ;
164172
173+ if text_flag && tag {
174+ return Err ( ChecksumError :: TextAfterTag . into ( ) ) ;
175+ }
176+
165177 if check {
166178 // cksum does not support '--check'ing legacy algorithms
167179 if algo. is_some_and ( AlgoKind :: is_legacy) {
168180 return Err ( ChecksumError :: AlgorithmNotSupportedWithCheck . into ( ) ) ;
169181 }
170-
171- let text_flag = matches. get_flag ( options:: TEXT ) ;
172- let binary_flag = matches. get_flag ( options:: BINARY ) ;
173- let tag = matches. get_flag ( options:: TAG ) ;
174-
175- if tag || binary_flag || text_flag {
182+ // Maybe, we should just use clap
183+ if tag {
184+ return Err ( ChecksumError :: TagCheck . into ( ) ) ;
185+ }
186+ if binary_flag || text_flag {
176187 return Err ( ChecksumError :: BinaryTextConflict . into ( ) ) ;
177188 }
178189
0 commit comments