add -n flag to print to print without a newline (#5458)

* add -n flag to print to print without a newline

* clippy
This commit is contained in:
Darren Schroeder
2022-05-06 15:33:00 -05:00
committed by GitHub
parent fbdb125141
commit 2dfd975940
4 changed files with 28 additions and 7 deletions

View File

@ -16,6 +16,11 @@ impl Command for Print {
fn signature(&self) -> Signature {
Signature::build("print")
.rest("rest", SyntaxShape::Any, "the values to print")
.switch(
"no_newline",
"print without inserting a newline for the line ending",
Some('n'),
)
.category(Category::Strings)
}
@ -31,10 +36,13 @@ impl Command for Print {
_input: PipelineData,
) -> Result<PipelineData, ShellError> {
let args: Vec<Value> = call.rest(engine_state, stack, 0)?;
let no_newline = call.has_flag("no_newline");
let head = call.head;
for arg in args {
arg.into_pipeline_data().print(engine_state, stack)?;
arg.into_pipeline_data()
.print(engine_state, stack, no_newline)?;
}
Ok(PipelineData::new(head))

View File

@ -237,7 +237,7 @@ pub fn eval_source(
set_last_exit_code(stack, 0);
}
if let Err(err) = pipeline_data.print(engine_state, stack) {
if let Err(err) = pipeline_data.print(engine_state, stack, false) {
let working_set = StateWorkingSet::new(engine_state);
report_error(&working_set, &err);