nushell/src/commands/rm.rs

54 lines
1.4 KiB
Rust
Raw Normal View History

use crate::commands::command::RunnablePerItemContext;
use crate::context::CommandRegistry;
use crate::prelude::*;
use nu_errors::ShellError;
use nu_protocol::{CallInfo, Signature, SyntaxShape, Value};
use nu_source::Tagged;
2019-08-02 21:15:07 +02:00
use std::path::PathBuf;
2019-07-17 21:51:18 +02:00
pub struct Remove;
#[derive(Deserialize)]
pub struct RemoveArgs {
2019-08-21 19:03:59 +02:00
pub target: Tagged<PathBuf>,
pub recursive: Tagged<bool>,
pub trash: Tagged<bool>,
}
2019-08-15 07:02:02 +02:00
impl PerItemCommand for Remove {
2019-07-17 21:51:18 +02:00
fn name(&self) -> &str {
"rm"
}
2019-08-02 21:15:07 +02:00
fn signature(&self) -> Signature {
Signature::build("rm")
2019-10-28 06:15:35 +01: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 21:15:07 +02:00
}
2019-07-17 21:51:18 +02:00
fn usage(&self) -> &str {
2019-10-28 06:15:35 +01:00
"Remove a file"
}
2019-08-02 21:15:07 +02:00
fn run(
&self,
2019-08-15 07:02:02 +02:00
call_info: &CallInfo,
_registry: &CommandRegistry,
2019-08-29 05:53:45 +02:00
raw_args: &RawCommandArgs,
_input: Value,
2019-08-24 21:36:19 +02:00
) -> Result<OutputStream, ShellError> {
call_info
.process(&raw_args.shell_manager, raw_args.ctrl_c.clone(), rm)?
.run()
2019-07-17 21:51:18 +02:00
}
}
2019-08-24 21:36:19 +02:00
fn rm(args: RemoveArgs, context: &RunnablePerItemContext) -> Result<OutputStream, ShellError> {
2019-08-21 19:03:59 +02:00
let shell_manager = context.shell_manager.clone();
shell_manager.rm(args, context)
2019-07-17 21:51:18 +02:00
}