@@ -74,42 +74,6 @@ mod options {
7474/// Returns a pair of boolean. The first one indicates if we should use tagged
7575/// output format, the second one indicates if we should use the binary flag in
7676/// the untagged case.
77- fn handle_tag_text_binary_flags < S : AsRef < OsStr > > (
78- args : impl Iterator < Item = S > ,
79- ) -> UResult < ( bool , bool ) > {
80- let mut tag = true ;
81- let mut binary = false ;
82- let mut text = false ;
83-
84- // --binary, --tag and --untagged are tight together: none of them
85- // conflicts with each other but --tag will reset "binary" and "text" and
86- // set "tag".
87-
88- for arg in args {
89- let arg = arg. as_ref ( ) ;
90- if arg == "-b" || arg == "--binary" {
91- text = false ;
92- binary = true ;
93- } else if arg == "--text" {
94- text = true ;
95- binary = false ;
96- } else if arg == "--tag" {
97- tag = true ;
98- binary = false ;
99- text = false ;
100- } else if arg == "--untagged" {
101- tag = false ;
102- }
103- }
104-
105- // Specifying --text without ever mentioning --untagged fails.
106- if text && tag {
107- return Err ( ChecksumError :: TextWithoutUntagged . into ( ) ) ;
108- }
109-
110- Ok ( ( tag, binary) )
111- }
112-
11377/// Sanitize the `--length` argument depending on `--algorithm` and `--length`.
11478fn maybe_sanitize_length (
11579 algo_cli : Option < AlgoKind > ,
@@ -200,7 +164,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
200164 // Set the default algorithm to CRC when not '--check'ing.
201165 let algo_kind = algo_cli. unwrap_or ( AlgoKind :: Crc ) ;
202166
203- let ( tag, binary) = handle_tag_text_binary_flags ( std:: env:: args_os ( ) ) ?;
167+ let tag = matches. get_flag ( options:: TAG ) || !matches. get_flag ( options:: UNTAGGED ) ;
168+ let binary = matches. get_flag ( options:: BINARY ) ;
204169
205170 let algo = SizedAlgoKind :: from_unsized ( algo_kind, length) ?;
206171 let line_ending = LineEnding :: from_zero_flag ( matches. get_flag ( options:: ZERO ) ) ;
@@ -257,7 +222,9 @@ pub fn uu_app() -> Command {
257222 . long ( options:: TAG )
258223 . help ( translate ! ( "cksum-help-tag" ) )
259224 . action ( ArgAction :: SetTrue )
260- . overrides_with ( options:: UNTAGGED ) ,
225+ . overrides_with ( options:: UNTAGGED )
226+ . overrides_with ( options:: BINARY )
227+ . overrides_with ( options:: TEXT ) ,
261228 )
262229 . arg (
263230 Arg :: new ( options:: LENGTH )
@@ -301,7 +268,8 @@ pub fn uu_app() -> Command {
301268 . short ( 't' )
302269 . hide ( true )
303270 . overrides_with ( options:: BINARY )
304- . action ( ArgAction :: SetTrue ) ,
271+ . action ( ArgAction :: SetTrue )
272+ . requires ( options:: UNTAGGED ) ,
305273 )
306274 . arg (
307275 Arg :: new ( options:: BINARY )
0 commit comments