Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/uu/link/locales/en-US.ftl
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
link-about = Call the link function to create a link named FILE2 to an existing FILE1.
link-usage = link FILE1 FILE2

link-error-cannot-create-link = cannot create link { $new } to { $old }
5 changes: 5 additions & 0 deletions src/uu/link/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
link-about = Appelle la fonction link pour créer un lien nommé FILE2 vers un FILE1 existant.
link-usage = link FILE1 FILE2

# Messages d'erreur
link-error-cannot-create-link = impossible de créer le lien { $new } vers { $old }
18 changes: 13 additions & 5 deletions src/uu/link/src/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

use clap::builder::ValueParser;
use clap::{Arg, Command};
use std::collections::HashMap;
use std::ffi::OsString;
use std::fs::hard_link;
use std::path::Path;
use uucore::display::Quotable;
use uucore::error::{FromIo, UResult};
use uucore::format_usage;

use uucore::locale::get_message;
use uucore::locale::{get_message, get_message_with_args};

pub mod options {
pub static FILES: &str = "FILES";
Expand All @@ -20,16 +21,23 @@ pub mod options {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().try_get_matches_from(args)?;

let files: Vec<_> = matches
.get_many::<OsString>(options::FILES)
.unwrap_or_default()
.collect();

let old = Path::new(files[0]);
let new = Path::new(files[1]);

hard_link(old, new)
.map_err_context(|| format!("cannot create link {} to {}", new.quote(), old.quote()))
hard_link(old, new).map_err_context(|| {
get_message_with_args(
"link-error-cannot-create-link",
HashMap::from([
("new".to_string(), new.quote().to_string()),
("old".to_string(), old.quote().to_string()),
]),
)
})
}

pub fn uu_app() -> Command {
Expand Down
Loading