@@ -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,24 @@ 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+ // todo: we should fail with additional args https://github.com/uutils/coreutils/issues/11383#issuecomment-4082564058
80+ // but it needs to patch busybox test suite
81+ //if args.next().is_some() && !binary_as_util.ends_with("box") {
82+ if args. next ( ) . is_some ( ) {
83+ let _ = writeln ! ( stderr( ) , "coreutils: invalid sub-command" ) ;
84+ process:: exit ( 1 ) ;
8385 }
84- let utils: Vec < _ > = utils. keys ( ) . collect ( ) ;
85- for util in utils {
86- println ! ( "{util}" ) ;
86+ let mut out = stdout ( ) . lock ( ) ;
87+ for util in utils. keys ( ) {
88+ if let Err ( e) = writeln ! ( out, "{util}" ) {
89+ let _ = writeln ! ( stderr( ) , "coreutils: {e}" ) ;
90+ process:: exit ( 1 ) ;
91+ }
8792 }
8893 process:: exit ( 0 ) ;
8994 }
9095 "--version" | "-V" => {
91- println ! ( "{binary_as_util} {VERSION} (multi-call binary)" ) ;
96+ println ! ( "coreutils {VERSION} (multi-call binary)" ) ;
9297 process:: exit ( 0 ) ;
9398 }
9499 // Not a special command: fallthrough to calling a util
@@ -120,7 +125,7 @@ fn main() {
120125 . into_iter ( )
121126 . chain ( args) ,
122127 ) ;
123- io :: stdout ( ) . flush ( ) . expect ( "could not flush stdout" ) ;
128+ stdout ( ) . flush ( ) . expect ( "could not flush stdout" ) ;
124129 process:: exit ( code) ;
125130 }
126131 None => validation:: not_found ( & util_os) ,
@@ -137,8 +142,14 @@ fn main() {
137142 }
138143 }
139144 } else {
140- // no arguments provided
141- usage ( & utils, binary_as_util) ;
142- process:: exit ( 0 ) ;
145+ // GNU exit(1), but busybox tests needs exit(0)
146+ // todo: patch the test suite instead
147+ if binary_as_util. ends_with ( "box" ) {
148+ usage ( & utils, binary_as_util) ;
149+ process:: exit ( 0 ) ;
150+ } else {
151+ let _ = writeln ! ( stderr( ) , "coreutils: missing argument" ) ;
152+ process:: exit ( 1 ) ;
153+ }
143154 }
144155}
0 commit comments