@@ -50,12 +50,12 @@ pub struct Config<'a> {
5050}
5151
5252#[ cfg( windows) ]
53- fn get_mode ( _matches : & ArgMatches , _mode_had_minus_prefix : bool ) -> Result < u32 , String > {
53+ fn get_mode ( _matches : & ArgMatches ) -> Result < u32 , String > {
5454 Ok ( DEFAULT_PERM )
5555}
5656
5757#[ cfg( not( windows) ) ]
58- fn get_mode ( matches : & ArgMatches , mode_had_minus_prefix : bool ) -> Result < u32 , String > {
58+ fn get_mode ( matches : & ArgMatches ) -> Result < u32 , String > {
5959 // Not tested on Windows
6060 let mut new_mode = DEFAULT_PERM ;
6161
@@ -64,13 +64,7 @@ fn get_mode(matches: &ArgMatches, mode_had_minus_prefix: bool) -> Result<u32, St
6464 if mode. chars ( ) . any ( |c| c. is_ascii_digit ( ) ) {
6565 new_mode = mode:: parse_numeric ( new_mode, m, true ) ?;
6666 } else {
67- let cmode = if mode_had_minus_prefix {
68- // clap parsing is finished, now put prefix back
69- format ! ( "-{mode}" )
70- } else {
71- mode. to_string ( )
72- } ;
73- new_mode = mode:: parse_symbolic ( new_mode, & cmode, mode:: get_umask ( ) , true ) ?;
67+ new_mode = mode:: parse_symbolic ( new_mode, mode, mode:: get_umask ( ) , true ) ?;
7468 }
7569 }
7670 Ok ( new_mode)
@@ -80,42 +74,8 @@ fn get_mode(matches: &ArgMatches, mode_had_minus_prefix: bool) -> Result<u32, St
8074 }
8175}
8276
83- #[ cfg( windows) ]
84- fn strip_minus_from_mode ( _args : & mut [ OsString ] ) -> UResult < bool > {
85- Ok ( false )
86- }
87-
88- // Iterate 'args' and delete the first occurrence
89- // of a prefix '-' if it's associated with MODE
90- // e.g. "chmod -v -xw -R FILE" -> "chmod -v xw -R FILE"
91- #[ cfg( not( windows) ) ]
92- fn strip_minus_from_mode ( args : & mut Vec < OsString > ) -> UResult < bool > {
93- for arg in args {
94- if arg == "--" {
95- break ;
96- }
97- let bytes = uucore:: os_str_as_bytes ( arg) ?;
98- if let Some ( b'-' ) = bytes. first ( ) {
99- if let Some (
100- b'r' | b'w' | b'x' | b'X' | b's' | b't' | b'u' | b'g' | b'o' | b'0' ..=b'7' ,
101- ) = bytes. get ( 1 )
102- {
103- * arg = uucore:: os_str_from_bytes ( & bytes[ 1 ..] ) ?. into_owned ( ) ;
104- return Ok ( true ) ;
105- }
106- }
107- }
108- Ok ( false )
109- }
110-
11177#[ uucore:: main]
11278pub fn uumain ( args : impl uucore:: Args ) -> UResult < ( ) > {
113- let mut args: Vec < OsString > = args. collect ( ) ;
114-
115- // Before we can parse 'args' with clap (and previously getopts),
116- // a possible MODE prefix '-' needs to be removed (e.g. "chmod -x FILE").
117- let mode_had_minus_prefix = strip_minus_from_mode ( & mut args) ?;
118-
11979 // Linux-specific options, not implemented
12080 // opts.optflag("Z", "context", "set SELinux security context" +
12181 // " of each created directory to CTX"),
@@ -133,7 +93,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
13393 let set_selinux_context = matches. get_flag ( options:: SELINUX ) ;
13494 let context = matches. get_one :: < String > ( options:: CONTEXT ) ;
13595
136- match get_mode ( & matches, mode_had_minus_prefix ) {
96+ match get_mode ( & matches) {
13797 Ok ( mode) => {
13898 let config = Config {
13999 recursive,
@@ -158,7 +118,9 @@ pub fn uu_app() -> Command {
158118 Arg :: new ( options:: MODE )
159119 . short ( 'm' )
160120 . long ( options:: MODE )
161- . help ( translate ! ( "mkdir-help-mode" ) ) ,
121+ . help ( translate ! ( "mkdir-help-mode" ) )
122+ . allow_hyphen_values ( true )
123+ . num_args ( 1 ) ,
162124 )
163125 . arg (
164126 Arg :: new ( options:: PARENTS )
0 commit comments