77#![ allow( clippy:: upper_case_acronyms) ]
88
99use clap:: builder:: ValueParser ;
10- use uucore:: LocalizedCommand ;
1110use uucore:: error:: { UResult , USimpleError , UUsageError } ;
1211use uucore:: translate;
1312use uucore:: { display:: Quotable , format_usage, show_error, show_warning} ;
@@ -155,20 +154,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
155154}
156155
157156pub fn uu_app ( ) -> Command {
158- Command :: new ( uucore:: util_name ( ) )
157+ let cmd = Command :: new ( uucore:: util_name ( ) )
159158 . version ( uucore:: crate_version!( ) )
160- . help_template ( uucore:: localized_help_template ( uucore:: util_name ( ) ) )
161159 . about ( translate ! ( "chcon-about" ) )
162160 . override_usage ( format_usage ( & translate ! ( "chcon-usage" ) ) )
163- . infer_long_args ( true )
164- . disable_help_flag ( true )
161+ . infer_long_args ( true ) ;
162+ uucore :: clap_localization :: configure_localized_command ( cmd )
165163 . args_override_self ( true )
166- . arg (
167- Arg :: new ( options:: HELP )
168- . long ( options:: HELP )
169- . help ( translate ! ( "chcon-help-help" ) )
170- . action ( ArgAction :: Help ) ,
171- )
164+ . disable_help_flag ( true )
172165 . arg (
173166 Arg :: new ( options:: dereference:: DEREFERENCE )
174167 . long ( options:: dereference:: DEREFERENCE )
@@ -183,6 +176,12 @@ pub fn uu_app() -> Command {
183176 . help ( translate ! ( "chcon-help-no-dereference" ) )
184177 . action ( ArgAction :: SetTrue ) ,
185178 )
179+ . arg (
180+ Arg :: new ( "help" )
181+ . long ( "help" )
182+ . help ( translate ! ( "help" ) )
183+ . action ( ArgAction :: Help ) ,
184+ )
186185 . arg (
187186 Arg :: new ( options:: preserve_root:: PRESERVE_ROOT )
188187 . long ( options:: preserve_root:: PRESERVE_ROOT )
@@ -305,7 +304,18 @@ struct Options {
305304}
306305
307306fn parse_command_line ( config : Command , args : impl uucore:: Args ) -> Result < Options > {
308- let matches = config. get_matches_from_localized ( args) ;
307+ let matches = match config. try_get_matches_from ( args) {
308+ Ok ( matches) => matches,
309+ Err ( e) if e. exit_code ( ) == 0 => {
310+ // Help/version - use the error's print method which respects the Command's color settings
311+ e. print ( ) . expect ( "Failed to print help" ) ;
312+ std:: process:: exit ( 0 ) ;
313+ }
314+ Err ( e) => {
315+ // Other errors - use localized error handling
316+ uucore:: clap_localization:: handle_clap_error_with_exit_code ( e, 1 ) ;
317+ }
318+ } ;
309319
310320 let verbose = matches. get_flag ( options:: VERBOSE ) ;
311321
0 commit comments