2019-08-20 11:20:48 +00:00
|
|
|
use crate::commands::command::RunnablePerItemContext;
|
2019-07-17 19:51:18 +00:00
|
|
|
use crate::errors::ShellError;
|
2019-09-14 16:30:24 +00:00
|
|
|
use crate::parser::hir::SyntaxShape;
|
2019-08-20 11:20:48 +00:00
|
|
|
use crate::parser::registry::{CommandRegistry, Signature};
|
2019-07-20 02:27:10 +00:00
|
|
|
use crate::prelude::*;
|
2019-11-21 14:33:14 +00:00
|
|
|
use nu_source::Tagged;
|
2019-08-02 19:15:07 +00:00
|
|
|
use std::path::PathBuf;
|
2019-07-17 19:51:18 +00:00
|
|
|
|
|
|
|
pub struct Remove;
|
|
|
|
|
2019-08-20 11:20:48 +00:00
|
|
|
#[derive(Deserialize)]
|
|
|
|
pub struct RemoveArgs {
|
2019-08-21 17:03:59 +00:00
|
|
|
pub target: Tagged<PathBuf>,
|
|
|
|
pub recursive: Tagged<bool>,
|
2019-10-18 22:41:24 +00:00
|
|
|
pub trash: Tagged<bool>,
|
2019-08-20 11:20:48 +00:00
|
|
|
}
|
|
|
|
|
2019-08-15 05:02:02 +00:00
|
|
|
impl PerItemCommand for Remove {
|
2019-07-17 19:51:18 +00:00
|
|
|
fn name(&self) -> &str {
|
|
|
|
"rm"
|
|
|
|
}
|
|
|
|
|
2019-08-02 19:15:07 +00:00
|
|
|
fn signature(&self) -> Signature {
|
|
|
|
Signature::build("rm")
|
2019-10-28 05:15:35 +00:00
|
|
|
.required("path", SyntaxShape::Pattern, "the file path to remove")
|
|
|
|
.switch(
|
|
|
|
"trash",
|
|
|
|
"use the platform's recycle bin instead of permanently deleting",
|
|
|
|
)
|
|
|
|
.switch("recursive", "delete subdirectories recursively")
|
2019-08-02 19:15:07 +00:00
|
|
|
}
|
2019-07-17 19:51:18 +00:00
|
|
|
|
2019-08-29 22:52:32 +00:00
|
|
|
fn usage(&self) -> &str {
|
2019-10-28 05:15:35 +00:00
|
|
|
"Remove a file"
|
2019-08-29 22:52:32 +00:00
|
|
|
}
|
|
|
|
|
2019-08-02 19:15:07 +00:00
|
|
|
fn run(
|
|
|
|
&self,
|
2019-08-15 05:02:02 +00:00
|
|
|
call_info: &CallInfo,
|
|
|
|
_registry: &CommandRegistry,
|
2019-08-29 03:53:45 +00:00
|
|
|
raw_args: &RawCommandArgs,
|
2019-11-21 14:33:14 +00:00
|
|
|
_input: Value,
|
2019-08-24 19:36:19 +00:00
|
|
|
) -> Result<OutputStream, ShellError> {
|
2019-08-29 03:53:45 +00:00
|
|
|
call_info.process(&raw_args.shell_manager, rm)?.run()
|
2019-07-17 19:51:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-24 19:36:19 +00:00
|
|
|
fn rm(args: RemoveArgs, context: &RunnablePerItemContext) -> Result<OutputStream, ShellError> {
|
2019-08-21 17:03:59 +00:00
|
|
|
let shell_manager = context.shell_manager.clone();
|
|
|
|
shell_manager.rm(args, context)
|
2019-07-17 19:51:18 +00:00
|
|
|
}
|