diff --git a/crates/nu-command/src/commands/filesystem/rm.rs b/crates/nu-command/src/commands/filesystem/rm.rs index 35c3762dd..2769b7939 100644 --- a/crates/nu-command/src/commands/filesystem/rm.rs +++ b/crates/nu-command/src/commands/filesystem/rm.rs @@ -2,7 +2,8 @@ use crate::prelude::*; use nu_engine::shell::RemoveArgs; use nu_engine::WholeStreamCommand; use nu_errors::ShellError; -use nu_protocol::{Signature, SyntaxShape}; +use nu_protocol::{Primitive, Signature, SyntaxShape, UntaggedValue}; +use nu_source::Tagged; pub struct Remove; @@ -66,7 +67,7 @@ fn rm(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); let shell_manager = args.shell_manager(); - let args = RemoveArgs { + let mut rm_args = RemoveArgs { rest: args.rest(0)?, recursive: args.has_flag("recursive"), trash: args.has_flag("trash"), @@ -74,7 +75,7 @@ fn rm(args: CommandArgs) -> Result { force: args.has_flag("force"), }; - if args.trash && args.permanent { + if rm_args.trash && rm_args.permanent { return Ok(ActionStream::one(Err(ShellError::labeled_error( "only one of --permanent and --trash can be used", "conflicting flags", @@ -82,7 +83,19 @@ fn rm(args: CommandArgs) -> Result { )))); } - shell_manager.rm(args, name) + if rm_args.rest.is_empty() { + let mut input_peek = args.input.peekable(); + while let Some(v) = &input_peek.next() { + if let UntaggedValue::Primitive(Primitive::FilePath(path)) = &v.value { + rm_args.rest.push(Tagged { + item: path.to_path_buf(), + tag: args.call_info.name_tag.clone(), + }) + }; + } + } + + shell_manager.rm(rm_args, name) } #[cfg(test)]