implement --link and --symbolic-link

This commit is contained in:
Jasha 2024-11-17 10:23:54 -05:00
parent c3e99bb597
commit 0c812bfbbf

View file

@ -47,6 +47,8 @@ impl Command for UCp {
) )
.switch("progress", "display a progress bar", Some('p')) .switch("progress", "display a progress bar", Some('p'))
.switch("no-clobber", "do not overwrite an existing file", Some('n')) .switch("no-clobber", "do not overwrite an existing file", Some('n'))
.switch("link", "hard-link files instead of copying", Some('l'))
.switch("symbolic-link", "make symbolic links instead of copying", Some('s'))
.named( .named(
"preserve", "preserve",
SyntaxShape::List(Box::new(SyntaxShape::String)), SyntaxShape::List(Box::new(SyntaxShape::String)),
@ -109,10 +111,19 @@ impl Command for UCp {
_input: PipelineData, _input: PipelineData,
) -> Result<PipelineData, ShellError> { ) -> Result<PipelineData, ShellError> {
let interactive = call.has_flag(engine_state, stack, "interactive")?; let interactive = call.has_flag(engine_state, stack, "interactive")?;
let (update, copy_mode) = if call.has_flag(engine_state, stack, "update")? { let update = if call.has_flag(engine_state, stack, "update")? {
(UpdateMode::ReplaceIfOlder, CopyMode::Update) UpdateMode::ReplaceIfOlder
} else { } else {
(UpdateMode::ReplaceAll, CopyMode::Copy) UpdateMode::ReplaceAll
};
let copy_mode = if call.has_flag(engine_state, stack, "link")? {
CopyMode::Link
} else if call.has_flag(engine_state, stack, "symbolic-link")? {
CopyMode::SymLink
} else if call.has_flag(engine_state, stack, "update")? {
CopyMode::Update
} else {
CopyMode::Copy
}; };
let force = call.has_flag(engine_state, stack, "force")?; let force = call.has_flag(engine_state, stack, "force")?;