From 926177235c4d7a5e011c08e24327e551910ed3e1 Mon Sep 17 00:00:00 2001 From: Robert O'Shea Date: Fri, 11 Feb 2022 23:22:40 +0000 Subject: [PATCH] Added quiet flag rm command #4423 (#4430) * rm now uses -f flag to not print anything * changed quiet flag to q not f * Changed value passed to Value::Nothing in rm command --- crates/nu-command/src/filesystem/rm.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/nu-command/src/filesystem/rm.rs b/crates/nu-command/src/filesystem/rm.rs index 95bb8b2cef..dc6f1c0520 100644 --- a/crates/nu-command/src/filesystem/rm.rs +++ b/crates/nu-command/src/filesystem/rm.rs @@ -13,7 +13,7 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ Category, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Span, Spanned, - SyntaxShape, Value, + SyntaxShape, Type, Value, }; const GLOB_PARAMS: glob::MatchOptions = glob::MatchOptions { @@ -48,6 +48,7 @@ impl Command for Rm { ) .switch("recursive", "delete subdirectories recursively", Some('r')) .switch("force", "suppress error when no file", Some('f')) + .switch("quiet", "supress output showing files deleted", Some('q')) // .switch("interactive", "ask user to confirm action", Some('i')) .rest( "rest", @@ -78,6 +79,7 @@ fn rm( let permanent = call.has_flag("permanent"); let recursive = call.has_flag("recursive"); let force = call.has_flag("force"); + let quiet = call.has_flag("quiet"); // let interactive = call.has_flag("interactive"); let ctrlc = engine_state.ctrlc.clone(); @@ -241,6 +243,8 @@ fn rm( Value::Error { error: ShellError::SpannedLabeledError(msg, e.to_string(), span), } + } else if quiet { + Value::Nothing { span } } else { let val = format!("deleted {:}", f.to_string_lossy()); Value::String { val, span } @@ -266,5 +270,6 @@ fn rm( } } }) + .filter(|x| !matches!(x.get_type(), Type::Nothing)) .into_pipeline_data(ctrlc)) }