2019-08-19 02:12:28 +02:00
|
|
|
use crate::commands::command::RunnablePerItemContext;
|
2019-08-14 22:08:10 +02:00
|
|
|
use crate::errors::ShellError;
|
2019-09-14 18:30:24 +02:00
|
|
|
use crate::parser::hir::SyntaxShape;
|
2019-08-14 22:08:10 +02:00
|
|
|
use crate::parser::registry::{CommandRegistry, Signature};
|
|
|
|
use crate::prelude::*;
|
2019-11-21 15:33:14 +01:00
|
|
|
use nu_source::Tagged;
|
2019-08-14 22:08:10 +02:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
pub struct Move;
|
|
|
|
|
2019-08-19 02:12:28 +02:00
|
|
|
#[derive(Deserialize)]
|
|
|
|
pub struct MoveArgs {
|
2019-08-21 19:03:59 +02:00
|
|
|
pub src: Tagged<PathBuf>,
|
|
|
|
pub dst: Tagged<PathBuf>,
|
2019-08-19 02:12:28 +02:00
|
|
|
}
|
|
|
|
|
2019-08-15 07:02:02 +02:00
|
|
|
impl PerItemCommand for Move {
|
2019-08-14 22:08:10 +02:00
|
|
|
fn name(&self) -> &str {
|
|
|
|
"mv"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn signature(&self) -> Signature {
|
2019-08-19 02:12:28 +02:00
|
|
|
Signature::build("mv")
|
2019-10-28 06:15:35 +01:00
|
|
|
.required(
|
|
|
|
"source",
|
|
|
|
SyntaxShape::Pattern,
|
|
|
|
"the location to move files/directories from",
|
|
|
|
)
|
|
|
|
.required(
|
|
|
|
"destination",
|
|
|
|
SyntaxShape::Path,
|
|
|
|
"the location to move files/directories to",
|
|
|
|
)
|
2019-08-14 22:08:10 +02:00
|
|
|
}
|
2019-08-20 13:23:34 +02:00
|
|
|
|
2019-08-30 00:52:32 +02:00
|
|
|
fn usage(&self) -> &str {
|
|
|
|
"Move files or directories."
|
|
|
|
}
|
|
|
|
|
2019-08-20 13:23:34 +02:00
|
|
|
fn run(
|
|
|
|
&self,
|
|
|
|
call_info: &CallInfo,
|
|
|
|
_registry: &CommandRegistry,
|
2019-08-29 05:53:45 +02:00
|
|
|
raw_args: &RawCommandArgs,
|
2019-11-21 15:33:14 +01:00
|
|
|
_input: Value,
|
2019-08-24 21:36:19 +02:00
|
|
|
) -> Result<OutputStream, ShellError> {
|
2019-08-29 05:53:45 +02:00
|
|
|
call_info.process(&raw_args.shell_manager, mv)?.run()
|
2019-08-20 13:23:34 +02:00
|
|
|
}
|
2019-08-14 22:08:10 +02:00
|
|
|
}
|
|
|
|
|
2019-08-24 21:36:19 +02:00
|
|
|
fn mv(args: MoveArgs, context: &RunnablePerItemContext) -> Result<OutputStream, ShellError> {
|
2019-08-21 19:03:59 +02:00
|
|
|
let shell_manager = context.shell_manager.clone();
|
|
|
|
shell_manager.mv(args, context)
|
2019-08-14 22:08:10 +02:00
|
|
|
}
|