7
7
#![ allow( clippy:: upper_case_acronyms) ]
8
8
9
9
use clap:: builder:: ValueParser ;
10
- use uucore:: LocalizedCommand ;
11
10
use uucore:: error:: { UResult , USimpleError , UUsageError } ;
12
11
use uucore:: translate;
13
12
use uucore:: { display:: Quotable , format_usage, show_error, show_warning} ;
14
13
15
- use clap:: { Arg , ArgAction , Command } ;
14
+ use clap:: { Arg , ArgAction , ArgMatches , Command } ;
16
15
use selinux:: { OpaqueSecurityContext , SecurityContext } ;
17
16
18
17
use std:: borrow:: Cow ;
@@ -58,9 +57,9 @@ pub mod options {
58
57
59
58
#[ uucore:: main]
60
59
pub fn uumain ( args : impl uucore:: Args ) -> UResult < ( ) > {
61
- let config = uu_app ( ) ;
60
+ let matches = uucore :: clap_localization :: handle_clap_result ( uu_app ( ) , args ) ? ;
62
61
63
- let options = match parse_command_line ( config , args ) {
62
+ let options = match parse_command_line ( & matches ) {
64
63
Ok ( r) => r,
65
64
Err ( r) => {
66
65
if let Error :: CommandLine ( r) = r {
@@ -155,20 +154,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
155
154
}
156
155
157
156
pub fn uu_app ( ) -> Command {
158
- Command :: new ( uucore:: util_name ( ) )
157
+ let cmd = Command :: new ( uucore:: util_name ( ) )
159
158
. version ( uucore:: crate_version!( ) )
160
- . help_template ( uucore:: localized_help_template ( uucore:: util_name ( ) ) )
161
159
. about ( translate ! ( "chcon-about" ) )
162
160
. 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 )
165
163
. 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 )
172
165
. arg (
173
166
Arg :: new ( options:: dereference:: DEREFERENCE )
174
167
. long ( options:: dereference:: DEREFERENCE )
@@ -183,6 +176,12 @@ pub fn uu_app() -> Command {
183
176
. help ( translate ! ( "chcon-help-no-dereference" ) )
184
177
. action ( ArgAction :: SetTrue ) ,
185
178
)
179
+ . arg (
180
+ Arg :: new ( "help" )
181
+ . long ( "help" )
182
+ . help ( translate ! ( "help" ) )
183
+ . action ( ArgAction :: Help ) ,
184
+ )
186
185
. arg (
187
186
Arg :: new ( options:: preserve_root:: PRESERVE_ROOT )
188
187
. long ( options:: preserve_root:: PRESERVE_ROOT )
@@ -304,9 +303,7 @@ struct Options {
304
303
files : Vec < PathBuf > ,
305
304
}
306
305
307
- fn parse_command_line ( config : Command , args : impl uucore:: Args ) -> Result < Options > {
308
- let matches = config. get_matches_from_localized ( args) ;
309
-
306
+ fn parse_command_line ( matches : & ArgMatches ) -> Result < Options > {
310
307
let verbose = matches. get_flag ( options:: VERBOSE ) ;
311
308
312
309
let ( recursive_mode, affect_symlink_referent) = if matches. get_flag ( options:: RECURSIVE ) {
0 commit comments