88use clap:: builder:: ValueParser ;
99use clap:: parser:: ValuesRef ;
1010use clap:: { Arg , ArgAction , ArgMatches , Command } ;
11+ use std:: collections:: HashMap ;
1112use std:: ffi:: OsString ;
1213use std:: path:: { Path , PathBuf } ;
1314#[ cfg( not( windows) ) ]
1415use uucore:: error:: FromIo ;
1516use uucore:: error:: { UResult , USimpleError } ;
16- use uucore:: locale:: get_message;
17+ use uucore:: locale:: { get_message, get_message_with_args } ;
1718#[ cfg( not( windows) ) ]
1819use uucore:: mode;
1920use uucore:: { display:: Quotable , fs:: dir_strip_dot_for_creation} ;
@@ -139,32 +140,35 @@ pub fn uu_app() -> Command {
139140 Arg :: new ( options:: MODE )
140141 . short ( 'm' )
141142 . long ( options:: MODE )
142- . help ( "set file mode (not implemented on windows)" ) ,
143+ . help ( get_message ( "mkdir-help- mode" ) ) ,
143144 )
144145 . arg (
145146 Arg :: new ( options:: PARENTS )
146147 . short ( 'p' )
147148 . long ( options:: PARENTS )
148- . help ( "make parent directories as needed" )
149+ . help ( get_message ( "mkdir-help-parents" ) )
149150 . overrides_with ( options:: PARENTS )
150151 . action ( ArgAction :: SetTrue ) ,
151152 )
152153 . arg (
153154 Arg :: new ( options:: VERBOSE )
154155 . short ( 'v' )
155156 . long ( options:: VERBOSE )
156- . help ( "print a message for each printed directory" )
157+ . help ( get_message ( "mkdir-help-verbose" ) )
157158 . action ( ArgAction :: SetTrue ) ,
158159 )
159160 . arg (
160161 Arg :: new ( options:: SELINUX )
161162 . short ( 'Z' )
162- . help ( "set SELinux security context of each created directory to the default type" )
163+ . help ( get_message ( "mkdir-help-selinux" ) )
163164 . action ( ArgAction :: SetTrue ) ,
164165 )
165- . arg ( Arg :: new ( options:: CONTEXT ) . long ( options:: CONTEXT ) . value_name ( "CTX" ) . help (
166- "like -Z, or if CTX is specified then set the SELinux or SMACK security context to CTX" ,
167- ) )
166+ . arg (
167+ Arg :: new ( options:: CONTEXT )
168+ . long ( options:: CONTEXT )
169+ . value_name ( "CTX" )
170+ . help ( get_message ( "mkdir-help-context" ) ) ,
171+ )
168172 . arg (
169173 Arg :: new ( options:: DIRS )
170174 . action ( ArgAction :: Append )
@@ -205,10 +209,9 @@ pub fn mkdir(path: &Path, config: &Config) -> UResult<()> {
205209 if path. as_os_str ( ) . is_empty ( ) {
206210 return Err ( USimpleError :: new (
207211 1 ,
208- "cannot create directory '': No such file or directory" . to_owned ( ) ,
212+ get_message ( "mkdir-error-empty- directory-name" ) ,
209213 ) ) ;
210214 }
211-
212215 // Special case to match GNU's behavior:
213216 // mkdir -p foo/. should work and just create foo/
214217 // std::fs::create_dir("foo/."); fails in pure Rust
@@ -222,8 +225,12 @@ fn chmod(path: &Path, mode: u32) -> UResult<()> {
222225 use std:: fs:: { Permissions , set_permissions} ;
223226 use std:: os:: unix:: fs:: PermissionsExt ;
224227 let mode = Permissions :: from_mode ( mode) ;
225- set_permissions ( path, mode)
226- . map_err_context ( || format ! ( "cannot set permissions {}" , path. quote( ) ) )
228+ set_permissions ( path, mode) . map_err_context ( || {
229+ get_message_with_args (
230+ "mkdir-error-cannot-set-permissions" ,
231+ HashMap :: from ( [ ( "path" . to_string ( ) , path. quote ( ) . to_string ( ) ) ] ) ,
232+ )
233+ } )
227234}
228235
229236#[ cfg( windows) ]
@@ -240,7 +247,10 @@ fn create_dir(path: &Path, is_parent: bool, config: &Config) -> UResult<()> {
240247 if path_exists && !config. recursive {
241248 return Err ( USimpleError :: new (
242249 1 ,
243- format ! ( "{}: File exists" , path. display( ) ) ,
250+ get_message_with_args (
251+ "mkdir-error-file-exists" ,
252+ HashMap :: from ( [ ( "path" . to_string ( ) , path. to_string_lossy ( ) . to_string ( ) ) ] ) ,
253+ ) ,
244254 ) ) ;
245255 }
246256 if path == Path :: new ( "" ) {
@@ -251,7 +261,7 @@ fn create_dir(path: &Path, is_parent: bool, config: &Config) -> UResult<()> {
251261 match path. parent ( ) {
252262 Some ( p) => create_dir ( p, true , config) ?,
253263 None => {
254- USimpleError :: new ( 1 , " failed to create whole tree") ;
264+ USimpleError :: new ( 1 , get_message ( "mkdir-error- failed-to- create- tree") ) ;
255265 }
256266 }
257267 }
@@ -260,9 +270,14 @@ fn create_dir(path: &Path, is_parent: bool, config: &Config) -> UResult<()> {
260270 Ok ( ( ) ) => {
261271 if config. verbose {
262272 println ! (
263- "{}: created directory {}" ,
264- uucore:: util_name( ) ,
265- path. quote( )
273+ "{}" ,
274+ get_message_with_args(
275+ "mkdir-verbose-created-directory" ,
276+ HashMap :: from( [
277+ ( "util_name" . to_string( ) , uucore:: util_name( ) . to_string( ) ) ,
278+ ( "path" . to_string( ) , path. quote( ) . to_string( ) )
279+ ] )
280+ )
266281 ) ;
267282 }
268283
0 commit comments