@@ -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,23 @@ 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+ let _ = writeln ! ( stderr( ) , "coreutils: invalid sub-command" ) ;
83+ process:: exit ( 1 ) ;
8384 }
84- let utils: Vec < _ > = utils. keys ( ) . collect ( ) ;
85- for util in utils {
86- println ! ( "{util}" ) ;
85+ let mut out = stdout ( ) . lock ( ) ;
86+ for util in utils. keys ( ) {
87+ if let Err ( e) = writeln ! ( out, "{util}" ) {
88+ let _ = writeln ! ( stderr( ) , "coreutils: {e}" ) ;
89+ process:: exit ( 1 ) ;
90+ }
8791 }
8892 process:: exit ( 0 ) ;
8993 }
9094 "--version" | "-V" => {
91- println ! ( "{binary_as_util} {VERSION} (multi-call binary)" ) ;
95+ println ! ( "coreutils {VERSION} (multi-call binary)" ) ;
9296 process:: exit ( 0 ) ;
9397 }
9498 // Not a special command: fallthrough to calling a util
@@ -120,7 +124,7 @@ fn main() {
120124 . into_iter ( )
121125 . chain ( args) ,
122126 ) ;
123- io :: stdout ( ) . flush ( ) . expect ( "could not flush stdout" ) ;
127+ stdout ( ) . flush ( ) . expect ( "could not flush stdout" ) ;
124128 process:: exit ( code) ;
125129 }
126130 None => validation:: not_found ( & util_os) ,
@@ -137,8 +141,14 @@ fn main() {
137141 }
138142 }
139143 } else {
140- // no arguments provided
141- usage ( & utils, binary_as_util) ;
142- process:: exit ( 0 ) ;
144+ // GNU exit(1), but busybox tests needs exit(0)
145+ // todo: patch the test suite instead
146+ if binary_as_util. ends_with ( "box" ) {
147+ usage ( & utils, binary_as_util) ;
148+ process:: exit ( 0 ) ;
149+ } else {
150+ let _ = writeln ! ( stderr( ) , "coreutils: missing argument" ) ;
151+ process:: exit ( 1 ) ;
152+ }
143153 }
144154}
0 commit comments