File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -75,6 +75,11 @@ fn main() {
7575
7676 match util {
7777 "--list" => {
78+ // If --help is also present, show usage instead of list
79+ if args. any ( |arg| arg == "--help" || arg == "-h" ) {
80+ usage ( & utils, binary_as_util) ;
81+ process:: exit ( 0 ) ;
82+ }
7883 let mut utils: Vec < _ > = utils. keys ( ) . collect ( ) ;
7984 utils. sort ( ) ;
8085 for util in utils {
@@ -123,6 +128,9 @@ fn main() {
123128 }
124129 usage ( & utils, binary_as_util) ;
125130 process:: exit ( 0 ) ;
131+ } else if util. starts_with ( '-' ) {
132+ // Argument looks like an option but wasn't recognized
133+ validation:: unrecognized_option ( binary_as_util, & util_os) ;
126134 } else {
127135 validation:: not_found ( & util_os) ;
128136 }
Original file line number Diff line number Diff line change @@ -29,6 +29,16 @@ pub fn not_found(util: &OsStr) -> ! {
2929 process:: exit ( 1 ) ;
3030}
3131
32+ /// Prints an "unrecognized option" error and exits
33+ pub fn unrecognized_option ( binary_name : & str , option : & OsStr ) -> ! {
34+ eprintln ! (
35+ "{}: unrecognized option '{}'" ,
36+ binary_name,
37+ option. to_string_lossy( )
38+ ) ;
39+ process:: exit ( 1 ) ;
40+ }
41+
3242/// Sets up localization for a utility with proper error handling
3343pub fn setup_localization_or_exit ( util_name : & str ) {
3444 let util_name = get_canonical_util_name ( util_name) ;
You can’t perform that action at this time.
0 commit comments