@@ -50,12 +50,12 @@ pub struct Config<'a> {
50
50
}
51
51
52
52
#[ 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 > {
54
54
Ok ( DEFAULT_PERM )
55
55
}
56
56
57
57
#[ 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 > {
59
59
// Not tested on Windows
60
60
let mut new_mode = DEFAULT_PERM ;
61
61
@@ -64,13 +64,7 @@ fn get_mode(matches: &ArgMatches, mode_had_minus_prefix: bool) -> Result<u32, St
64
64
if mode. chars ( ) . any ( |c| c. is_ascii_digit ( ) ) {
65
65
new_mode = mode:: parse_numeric ( new_mode, m, true ) ?;
66
66
} 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 ) ?;
74
68
}
75
69
}
76
70
Ok ( new_mode)
@@ -80,48 +74,14 @@ fn get_mode(matches: &ArgMatches, mode_had_minus_prefix: bool) -> Result<u32, St
80
74
}
81
75
}
82
76
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
-
111
77
#[ uucore:: main]
112
78
pub 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
-
119
79
// Linux-specific options, not implemented
120
80
// opts.optflag("Z", "context", "set SELinux security context" +
121
81
// " of each created directory to CTX"),
122
82
let matches = uu_app ( )
123
83
. after_help ( get_message ( "mkdir-after-help" ) )
124
- . try_get_matches_from ( args) ?;
84
+ . try_get_matches_from ( args) ?; // Directly use 'args'
125
85
126
86
let dirs = matches
127
87
. get_many :: < OsString > ( options:: DIRS )
@@ -133,7 +93,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
133
93
let set_selinux_context = matches. get_flag ( options:: SELINUX ) ;
134
94
let context = matches. get_one :: < String > ( options:: CONTEXT ) ;
135
95
136
- match get_mode ( & matches, mode_had_minus_prefix) {
96
+ // Corrected call to get_mode
97
+ match get_mode ( & matches) {
137
98
Ok ( mode) => {
138
99
let config = Config {
139
100
recursive,
@@ -158,7 +119,9 @@ pub fn uu_app() -> Command {
158
119
Arg :: new ( options:: MODE )
159
120
. short ( 'm' )
160
121
. long ( options:: MODE )
161
- . help ( get_message ( "mkdir-help-mode" ) ) ,
122
+ . help ( get_message ( "mkdir-help-mode" ) )
123
+ . allow_hyphen_values ( true )
124
+ . num_args ( 1 ) ,
162
125
)
163
126
. arg (
164
127
Arg :: new ( options:: PARENTS )
0 commit comments