From eff9305eb3470f91e64fb65ee898e987d453e0ca Mon Sep 17 00:00:00 2001 From: Firegem Date: Sun, 13 Apr 2025 08:50:04 -0400 Subject: [PATCH] Allow spreading arguments of `kill` command (#15558) # Description This changes the signature of `kill` from `kill pid ...rest` to `kill ...pid`. # User-Facing Changes Users will now be able to spread a list of pids to the `kill` command, whereas they'd have to specify the first separately before. # Tests + Formatting :+1: # After Submitting --- crates/nu-command/src/platform/kill.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/crates/nu-command/src/platform/kill.rs b/crates/nu-command/src/platform/kill.rs index 4c374c98ca..d85e878231 100644 --- a/crates/nu-command/src/platform/kill.rs +++ b/crates/nu-command/src/platform/kill.rs @@ -18,12 +18,11 @@ impl Command for Kill { let signature = Signature::build("kill") .input_output_types(vec![(Type::Nothing, Type::Any)]) .allow_variants_without_examples(true) - .required( + .rest( "pid", SyntaxShape::Int, - "Process id of process that is to be killed.", + "Process ids of processes that are to be killed.", ) - .rest("rest", SyntaxShape::Int, "Rest of processes to kill.") .switch("force", "forcefully kill the process", Some('f')) .switch("quiet", "won't print anything to the console", Some('q')) .category(Category::Platform); @@ -51,12 +50,18 @@ impl Command for Kill { call: &Call, _input: PipelineData, ) -> Result { - let pid: i64 = call.req(engine_state, stack, 0)?; - let rest: Vec = call.rest(engine_state, stack, 1)?; + let pids: Vec = call.rest(engine_state, stack, 0)?; let force: bool = call.has_flag(engine_state, stack, "force")?; let signal: Option> = call.get_flag(engine_state, stack, "signal")?; let quiet: bool = call.has_flag(engine_state, stack, "quiet")?; + if pids.is_empty() { + return Err(ShellError::MissingParameter { + param_name: "pid".to_string(), + span: call.arguments_span(), + }); + } + if cfg!(unix) { if let ( true, @@ -83,7 +88,7 @@ impl Command for Kill { let mut cmd = build_kill_command( force, - std::iter::once(pid).chain(rest), + pids.iter().copied(), signal.map(|spanned| spanned.item as u32), );