@@ -157,11 +157,19 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
157157 } ;
158158 let check = matches. get_flag ( "check" ) ;
159159
160- let ignore_missing = matches. get_flag ( "ignore-missing" ) ;
161- let warn = matches. get_flag ( "warn" ) ;
162- let quiet = matches. get_flag ( "quiet" ) ;
163- let strict = matches. get_flag ( "strict" ) ;
164- let status = matches. get_flag ( "status" ) ;
160+ let check_flag = |flag| match ( check, matches. get_flag ( flag) ) {
161+ ( _, false ) => Ok ( false ) ,
162+ ( true , true ) => Ok ( true ) ,
163+ ( false , true ) => Err ( ChecksumError :: CheckOnlyFlag ( flag. into ( ) ) ) ,
164+ } ;
165+
166+ // Each of the following flags are only expected in --check mode.
167+ // If we encounter them otherwise, end with an error.
168+ let ignore_missing = check_flag ( "ignore-missing" ) ?;
169+ let warn = check_flag ( "warn" ) ?;
170+ let quiet = check_flag ( "quiet" ) ?;
171+ let strict = check_flag ( "strict" ) ?;
172+ let status = check_flag ( "status" ) ?;
165173
166174 // clap provides the default value -. So we unwrap() safety.
167175 let files = matches
@@ -292,40 +300,35 @@ pub fn uu_app_common() -> Command {
292300 . long ( options:: QUIET )
293301 . help ( translate ! ( "hashsum-help-quiet" ) )
294302 . action ( ArgAction :: SetTrue )
295- . overrides_with_all ( [ options:: STATUS , options:: WARN ] )
296- . requires ( options:: CHECK ) ,
303+ . overrides_with_all ( [ options:: STATUS , options:: WARN ] ) ,
297304 )
298305 . arg (
299306 Arg :: new ( options:: STATUS )
300307 . short ( 's' )
301308 . long ( "status" )
302309 . help ( translate ! ( "hashsum-help-status" ) )
303310 . action ( ArgAction :: SetTrue )
304- . overrides_with_all ( [ options:: QUIET , options:: WARN ] )
305- . requires ( options:: CHECK ) ,
311+ . overrides_with_all ( [ options:: QUIET , options:: WARN ] ) ,
306312 )
307313 . arg (
308314 Arg :: new ( options:: STRICT )
309315 . long ( "strict" )
310316 . help ( translate ! ( "hashsum-help-strict" ) )
311- . action ( ArgAction :: SetTrue )
312- . requires ( options:: CHECK ) ,
317+ . action ( ArgAction :: SetTrue ) ,
313318 )
314319 . arg (
315320 Arg :: new ( "ignore-missing" )
316321 . long ( "ignore-missing" )
317322 . help ( translate ! ( "hashsum-help-ignore-missing" ) )
318- . action ( ArgAction :: SetTrue )
319- . requires ( options:: CHECK ) ,
323+ . action ( ArgAction :: SetTrue ) ,
320324 )
321325 . arg (
322326 Arg :: new ( options:: WARN )
323327 . short ( 'w' )
324328 . long ( "warn" )
325329 . help ( translate ! ( "hashsum-help-warn" ) )
326330 . action ( ArgAction :: SetTrue )
327- . overrides_with_all ( [ options:: QUIET , options:: STATUS ] )
328- . requires ( options:: CHECK ) ,
331+ . overrides_with_all ( [ options:: QUIET , options:: STATUS ] ) ,
329332 )
330333 . arg (
331334 Arg :: new ( "zero" )
0 commit comments