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
This commit is contained in:
Robert O'Shea 2022-02-11 23:22:40 +00:00 committed by GitHub
parent 85d1a681c7
commit 926177235c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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))
}