Fixed printing of builtin kill command #4392 (#4447)

* Fixed printing of builtin kill command

* Fixed fmt and clippy issues for kill command

* Uncommented unintentional comments

* Fixed wrong code added in kill command

* Fixed more fmt issues with kill command
This commit is contained in:
Robert O'Shea 2022-02-13 02:18:27 +00:00 committed by GitHub
parent 73f94105a5
commit c5e7bccee5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,8 +2,8 @@ use nu_engine::CallExt;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ast::Call, span}; use nu_protocol::{ast::Call, span};
use nu_protocol::{ use nu_protocol::{
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, ShellError,
Value, Signature, Spanned, SyntaxShape, Value,
}; };
use std::process::{Command as CommandSys, Stdio}; use std::process::{Command as CommandSys, Stdio};
@ -128,9 +128,22 @@ impl Command for Kill {
.stderr(Stdio::null()); .stderr(Stdio::null());
} }
cmd.status().expect("failed to execute shell command"); let output = cmd.output().expect("failed to execute shell command");
let val = String::from(
Ok(Value::Nothing { span: call.head }.into_pipeline_data()) String::from_utf8(output.stdout)
.expect("failed to convert output to string")
.trim_end(),
);
if val.is_empty() {
Ok(Value::Nothing { span: call.head }.into_pipeline_data())
} else {
Ok(vec![Value::String {
val,
span: call.head,
}]
.into_iter()
.into_pipeline_data(engine_state.ctrlc.clone()))
}
} }
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {