2019-08-17 05:53:39 +02:00
|
|
|
use crate::commands::command::RunnablePerItemContext;
|
2019-07-22 04:23:02 +02:00
|
|
|
use crate::errors::ShellError;
|
|
|
|
use crate::parser::hir::SyntaxType;
|
2019-08-09 06:51:21 +02:00
|
|
|
use crate::parser::registry::{CommandRegistry, Signature};
|
2019-07-22 04:23:02 +02:00
|
|
|
use crate::prelude::*;
|
2019-08-14 22:04:44 +02:00
|
|
|
use std::path::PathBuf;
|
2019-07-22 04:23:02 +02:00
|
|
|
|
2019-08-14 22:04:44 +02:00
|
|
|
pub struct Cpy;
|
2019-07-22 04:23:02 +02:00
|
|
|
|
2019-08-17 05:53:39 +02:00
|
|
|
#[derive(Deserialize)]
|
|
|
|
pub struct CopyArgs {
|
2019-08-21 19:03:59 +02:00
|
|
|
pub src: Tagged<PathBuf>,
|
|
|
|
pub dst: Tagged<PathBuf>,
|
|
|
|
pub recursive: Tagged<bool>,
|
2019-08-17 05:53:39 +02:00
|
|
|
}
|
|
|
|
|
2019-08-15 07:02:02 +02:00
|
|
|
impl PerItemCommand for Cpy {
|
2019-08-09 06:51:21 +02:00
|
|
|
fn run(
|
|
|
|
&self,
|
2019-08-15 07:02:02 +02:00
|
|
|
call_info: &CallInfo,
|
|
|
|
_registry: &CommandRegistry,
|
|
|
|
shell_manager: &ShellManager,
|
2019-08-19 02:12:28 +02:00
|
|
|
_input: Tagged<Value>,
|
2019-08-15 07:02:02 +02:00
|
|
|
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
2019-08-17 05:53:39 +02:00
|
|
|
call_info.process(shell_manager, cp)?.run()
|
2019-07-22 04:23:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn name(&self) -> &str {
|
|
|
|
"cp"
|
|
|
|
}
|
|
|
|
|
2019-08-09 06:51:21 +02:00
|
|
|
fn signature(&self) -> Signature {
|
|
|
|
Signature::build("cp")
|
2019-08-21 14:08:23 +02:00
|
|
|
.required("src", SyntaxType::Path)
|
|
|
|
.required("dst", SyntaxType::Path)
|
2019-08-09 06:51:21 +02:00
|
|
|
.named("file", SyntaxType::Any)
|
|
|
|
.switch("recursive")
|
2019-07-22 04:23:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-21 14:08:23 +02:00
|
|
|
fn cp(
|
2019-08-21 19:03:59 +02:00
|
|
|
args: CopyArgs,
|
|
|
|
context: &RunnablePerItemContext,
|
2019-08-15 07:02:02 +02:00
|
|
|
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
2019-08-21 19:03:59 +02:00
|
|
|
let shell_manager = context.shell_manager.clone();
|
|
|
|
shell_manager.cp(args, context)
|
2019-07-23 07:51:22 +02:00
|
|
|
}
|