@@ -8,7 +8,7 @@ use coreutils::validation;
88use itertools:: Itertools as _;
99use std:: cmp;
1010use std:: ffi:: OsString ;
11- use std:: io:: { self , Write } ;
11+ use std:: io:: { Write , stderr , stdout } ;
1212use std:: process;
1313use uucore:: Args ;
1414
@@ -76,19 +76,22 @@ fn main() {
7676
7777 match util {
7878 "--list" => {
79- // If --help is also present, show usage instead of list
80- if args. any ( |arg| arg == "--help" || arg == "-h" ) {
81- usage ( & utils , binary_as_util ) ;
82- process:: exit ( 0 ) ;
79+ // we should fail with additional args https://github.com/uutils/coreutils/issues/11383#issuecomment-4082564058
80+ if args. next ( ) . is_some ( ) {
81+ let _ = writeln ! ( stderr ( ) , "coreutils: invalid sub-command" ) ;
82+ process:: exit ( 1 ) ;
8383 }
84- let utils: Vec < _ > = utils. keys ( ) . collect ( ) ;
85- for util in utils {
86- println ! ( "{util}" ) ;
84+ let mut out = stdout ( ) . lock ( ) ;
85+ for util in utils. keys ( ) {
86+ if let Err ( e) = writeln ! ( out, "{util}" ) {
87+ let _ = writeln ! ( stderr( ) , "coreutils: {e}" ) ;
88+ process:: exit ( 1 ) ;
89+ }
8790 }
8891 process:: exit ( 0 ) ;
8992 }
9093 "--version" | "-V" => {
91- println ! ( "{binary_as_util} {VERSION} (multi-call binary)" ) ;
94+ println ! ( "coreutils {VERSION} (multi-call binary)" ) ;
9295 process:: exit ( 0 ) ;
9396 }
9497 // Not a special command: fallthrough to calling a util
@@ -120,7 +123,7 @@ fn main() {
120123 . into_iter ( )
121124 . chain ( args) ,
122125 ) ;
123- io :: stdout ( ) . flush ( ) . expect ( "could not flush stdout" ) ;
126+ stdout ( ) . flush ( ) . expect ( "could not flush stdout" ) ;
124127 process:: exit ( code) ;
125128 }
126129 None => validation:: not_found ( & util_os) ,
@@ -137,8 +140,13 @@ fn main() {
137140 }
138141 }
139142 } else {
140- // no arguments provided
141- usage ( & utils, binary_as_util) ;
142- process:: exit ( 0 ) ;
143+ // GNU just fails, but busybox tests needs usage
144+ // todo: patch the test suite instead
145+ if binary_as_util. ends_with ( "box" ) {
146+ usage ( & utils, binary_as_util) ;
147+ } else {
148+ let _ = writeln ! ( stderr( ) , "coreutils: missing argument" ) ;
149+ }
150+ process:: exit ( 1 ) ;
143151 }
144152}
0 commit comments