nushell/crates/nu-command/src/commands/move_/mv.rs

76 lines
1.9 KiB
Rust
Raw Normal View History

2019-08-14 22:08:10 +02:00
use crate::prelude::*;
use nu_engine::WholeStreamCommand;
use nu_errors::ShellError;
use nu_protocol::{Signature, SyntaxShape};
2019-08-14 22:08:10 +02:00
2020-07-06 17:27:01 +02:00
pub struct Mv;
2019-08-14 22:08:10 +02:00
2020-07-06 17:27:01 +02:00
impl WholeStreamCommand for Mv {
2019-08-14 22:08:10 +02:00
fn name(&self) -> &str {
"mv"
}
fn signature(&self) -> Signature {
Signature::build("mv")
2019-10-28 06:15:35 +01:00
.required(
"source",
SyntaxShape::GlobPattern,
2019-10-28 06:15:35 +01:00
"the location to move files/directories from",
)
.required(
"destination",
SyntaxShape::FilePath,
2019-10-28 06:15:35 +01:00
"the location to move files/directories to",
)
2019-08-14 22:08:10 +02:00
}
fn usage(&self) -> &str {
"Move files or directories."
}
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
mv(args)
}
fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "Rename a file",
example: "mv before.txt after.txt",
result: None,
},
Example {
description: "Move a file into a directory",
example: "mv test.txt my/subdirectory",
result: None,
},
Example {
description: "Move many files into a directory",
example: "mv *.txt my/subdirectory",
result: None,
},
]
}
2019-08-14 22:08:10 +02:00
}
fn mv(args: CommandArgs) -> Result<ActionStream, ShellError> {
let name = args.call_info.name_tag.clone();
let shell_manager = args.shell_manager();
let (args, _) = args.process()?;
shell_manager.mv(args, name)
2019-08-14 22:08:10 +02:00
}
#[cfg(test)]
mod tests {
2020-07-06 17:27:01 +02:00
use super::Mv;
use super::ShellError;
#[test]
fn examples_work_as_expected() -> Result<(), ShellError> {
use crate::examples::test as test_examples;
2021-02-12 11:13:14 +01:00
test_examples(Mv {})
}
}