2
2
//
3
3
// For the full copyright and license information, please view the LICENSE
4
4
// file that was distributed with this source code.
5
+
5
6
use clap:: builder:: ValueParser ;
6
7
use clap:: { Arg , Command } ;
8
+ use std:: collections:: HashMap ;
7
9
use std:: ffi:: OsString ;
8
10
use std:: fs:: hard_link;
9
11
use std:: path:: Path ;
10
12
use uucore:: display:: Quotable ;
11
13
use uucore:: error:: { FromIo , UResult } ;
12
14
use uucore:: format_usage;
13
-
14
- use uucore:: locale:: get_message;
15
+ use uucore:: locale:: { get_message, get_message_with_args} ;
15
16
16
17
pub mod options {
17
18
pub static FILES : & str = "FILES" ;
@@ -20,16 +21,23 @@ pub mod options {
20
21
#[ uucore:: main]
21
22
pub fn uumain ( args : impl uucore:: Args ) -> UResult < ( ) > {
22
23
let matches = uu_app ( ) . try_get_matches_from ( args) ?;
23
-
24
24
let files: Vec < _ > = matches
25
25
. get_many :: < OsString > ( options:: FILES )
26
26
. unwrap_or_default ( )
27
27
. collect ( ) ;
28
+
28
29
let old = Path :: new ( files[ 0 ] ) ;
29
30
let new = Path :: new ( files[ 1 ] ) ;
30
31
31
- hard_link ( old, new)
32
- . map_err_context ( || format ! ( "cannot create link {} to {}" , new. quote( ) , old. quote( ) ) )
32
+ hard_link ( old, new) . map_err_context ( || {
33
+ get_message_with_args (
34
+ "link-error-cannot-create-link" ,
35
+ HashMap :: from ( [
36
+ ( "new" . to_string ( ) , new. quote ( ) . to_string ( ) ) ,
37
+ ( "old" . to_string ( ) , old. quote ( ) . to_string ( ) ) ,
38
+ ] ) ,
39
+ )
40
+ } )
33
41
}
34
42
35
43
pub fn uu_app ( ) -> Command {
0 commit comments