8
8
use clap:: { Arg , ArgAction , Command , value_parser} ;
9
9
use libc:: { S_IFBLK , S_IFCHR , S_IFIFO , S_IRGRP , S_IROTH , S_IRUSR , S_IWGRP , S_IWOTH , S_IWUSR } ;
10
10
use libc:: { dev_t, mode_t} ;
11
+ use std:: collections:: HashMap ;
11
12
use std:: ffi:: CString ;
12
13
13
14
use uucore:: display:: Quotable ;
14
15
use uucore:: error:: { UResult , USimpleError , UUsageError , set_exit_code} ;
15
16
use uucore:: format_usage;
16
-
17
- use uucore:: locale:: get_message;
17
+ use uucore:: locale:: { get_message, get_message_with_args} ;
18
18
19
19
const MODE_RW_UGO : mode_t = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH ;
20
20
@@ -130,14 +130,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
130
130
( FileType :: Fifo , _, _) => {
131
131
return Err ( UUsageError :: new (
132
132
1 ,
133
- "Fifos do not have major and minor device numbers." ,
133
+ get_message ( "mknod-error-fifo-no- major- minor" ) ,
134
134
) ) ;
135
135
}
136
136
( _, Some ( & major) , Some ( & minor) ) => makedev ( major, minor) ,
137
137
_ => {
138
138
return Err ( UUsageError :: new (
139
139
1 ,
140
- "Special files require major and minor device numbers." ,
140
+ get_message ( "mknod-error-special- require- major- minor" ) ,
141
141
) ) ;
142
142
}
143
143
} ;
@@ -166,38 +166,38 @@ pub fn uu_app() -> Command {
166
166
. short ( 'm' )
167
167
. long ( "mode" )
168
168
. value_name ( "MODE" )
169
- . help ( "set file permission bits to MODE, not a=rw - umask" ) ,
169
+ . help ( get_message ( "mknod-help-mode" ) ) ,
170
170
)
171
171
. arg (
172
172
Arg :: new ( "name" )
173
173
. value_name ( "NAME" )
174
- . help ( " name of the new file" )
174
+ . help ( get_message ( "mknod-help- name" ) )
175
175
. required ( true )
176
176
. value_hint ( clap:: ValueHint :: AnyPath ) ,
177
177
)
178
178
. arg (
179
179
Arg :: new ( options:: TYPE )
180
180
. value_name ( "TYPE" )
181
- . help ( " type of the new file (b, c, u or p)" )
181
+ . help ( get_message ( "mknod-help- type" ) )
182
182
. required ( true )
183
183
. value_parser ( parse_type) ,
184
184
)
185
185
. arg (
186
186
Arg :: new ( options:: MAJOR )
187
187
. value_name ( options:: MAJOR )
188
- . help ( " major file type" )
188
+ . help ( get_message ( "mknod-help- major" ) )
189
189
. value_parser ( value_parser ! ( u64 ) ) ,
190
190
)
191
191
. arg (
192
192
Arg :: new ( options:: MINOR )
193
193
. value_name ( options:: MINOR )
194
- . help ( " minor file type" )
194
+ . help ( get_message ( "mknod-help- minor" ) )
195
195
. value_parser ( value_parser ! ( u64 ) ) ,
196
196
)
197
197
. arg (
198
198
Arg :: new ( options:: SELINUX )
199
199
. short ( 'Z' )
200
- . help ( "set SELinux security context of each created directory to the default type" )
200
+ . help ( get_message ( "mknod-help-selinux" ) )
201
201
. action ( ArgAction :: SetTrue ) ,
202
202
)
203
203
. arg (
@@ -207,18 +207,23 @@ pub fn uu_app() -> Command {
207
207
. value_parser ( value_parser ! ( String ) )
208
208
. num_args ( 0 ..=1 )
209
209
. require_equals ( true )
210
- . help ( "like -Z, or if CTX is specified then set the SELinux or SMACK security context to CTX" )
210
+ . help ( get_message ( "mknod-help- context" ) ) ,
211
211
)
212
212
}
213
213
214
214
fn get_mode ( str_mode : Option < & String > ) -> Result < mode_t , String > {
215
215
match str_mode {
216
216
None => Ok ( MODE_RW_UGO ) ,
217
217
Some ( str_mode) => uucore:: mode:: parse_mode ( str_mode)
218
- . map_err ( |e| format ! ( "invalid mode ({e})" ) )
218
+ . map_err ( |e| {
219
+ get_message_with_args (
220
+ "mknod-error-invalid-mode" ,
221
+ HashMap :: from ( [ ( "error" . to_string ( ) , e. to_string ( ) ) ] ) ,
222
+ )
223
+ } )
219
224
. and_then ( |mode| {
220
225
if mode > 0o777 {
221
- Err ( " mode must specify only file permission bits" . to_string ( ) )
226
+ Err ( get_message ( "mknod-error- mode- permission- bits-only" ) )
222
227
} else {
223
228
Ok ( mode)
224
229
}
@@ -231,11 +236,14 @@ fn parse_type(tpe: &str) -> Result<FileType, String> {
231
236
// 'mknod /dev/rst0 character 18 0'.
232
237
tpe. chars ( )
233
238
. next ( )
234
- . ok_or_else ( || " missing device type". to_string ( ) )
239
+ . ok_or_else ( || get_message ( "mknod-error- missing- device- type") )
235
240
. and_then ( |first_char| match first_char {
236
241
'b' => Ok ( FileType :: Block ) ,
237
242
'c' | 'u' => Ok ( FileType :: Character ) ,
238
243
'p' => Ok ( FileType :: Fifo ) ,
239
- _ => Err ( format ! ( "invalid device type {}" , tpe. quote( ) ) ) ,
244
+ _ => Err ( get_message_with_args (
245
+ "mknod-error-invalid-device-type" ,
246
+ HashMap :: from ( [ ( "type" . to_string ( ) , tpe. quote ( ) . to_string ( ) ) ] ) ,
247
+ ) ) ,
240
248
} )
241
249
}
0 commit comments