51 lines
1.2 KiB
Rust
51 lines
1.2 KiB
Rust
use crate::commands::WholeStreamCommand;
|
|
use crate::context::CommandRegistry;
|
|
use crate::prelude::*;
|
|
use nu_errors::ShellError;
|
|
use nu_protocol::{Signature, SyntaxShape};
|
|
use nu_source::Tagged;
|
|
use std::path::PathBuf;
|
|
|
|
pub struct Cpy;
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct CopyArgs {
|
|
pub src: Tagged<PathBuf>,
|
|
pub dst: Tagged<PathBuf>,
|
|
pub recursive: Tagged<bool>,
|
|
}
|
|
|
|
impl WholeStreamCommand for Cpy {
|
|
fn name(&self) -> &str {
|
|
"cp"
|
|
}
|
|
|
|
fn signature(&self) -> Signature {
|
|
Signature::build("cp")
|
|
.required("src", SyntaxShape::Pattern, "the place to copy from")
|
|
.required("dst", SyntaxShape::Path, "the place to copy to")
|
|
.switch(
|
|
"recursive",
|
|
"copy recursively through subdirectories",
|
|
Some('r'),
|
|
)
|
|
}
|
|
|
|
fn usage(&self) -> &str {
|
|
"Copy files."
|
|
}
|
|
|
|
fn run(
|
|
&self,
|
|
args: CommandArgs,
|
|
registry: &CommandRegistry,
|
|
) -> Result<OutputStream, ShellError> {
|
|
args.process(registry, cp)?.run()
|
|
}
|
|
}
|
|
|
|
pub fn cp(args: CopyArgs, context: RunnableContext) -> Result<OutputStream, ShellError> {
|
|
let shell_manager = context.shell_manager.clone();
|
|
shell_manager.cp(args, &context)
|
|
}
|