mirror of
https://github.com/nushell/nushell.git
synced 2025-04-23 12:48:22 +02:00
Allow spreading arguments of kill
command (#15558)
<!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> This changes the signature of `kill` from `kill pid ...rest` to `kill ...pid`. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking 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 <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> 👍 # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
This commit is contained in:
parent
885b87a842
commit
eff9305eb3
@ -18,12 +18,11 @@ impl Command for Kill {
|
|||||||
let signature = Signature::build("kill")
|
let signature = Signature::build("kill")
|
||||||
.input_output_types(vec![(Type::Nothing, Type::Any)])
|
.input_output_types(vec![(Type::Nothing, Type::Any)])
|
||||||
.allow_variants_without_examples(true)
|
.allow_variants_without_examples(true)
|
||||||
.required(
|
.rest(
|
||||||
"pid",
|
"pid",
|
||||||
SyntaxShape::Int,
|
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("force", "forcefully kill the process", Some('f'))
|
||||||
.switch("quiet", "won't print anything to the console", Some('q'))
|
.switch("quiet", "won't print anything to the console", Some('q'))
|
||||||
.category(Category::Platform);
|
.category(Category::Platform);
|
||||||
@ -51,12 +50,18 @@ impl Command for Kill {
|
|||||||
call: &Call,
|
call: &Call,
|
||||||
_input: PipelineData,
|
_input: PipelineData,
|
||||||
) -> Result<PipelineData, ShellError> {
|
) -> Result<PipelineData, ShellError> {
|
||||||
let pid: i64 = call.req(engine_state, stack, 0)?;
|
let pids: Vec<i64> = call.rest(engine_state, stack, 0)?;
|
||||||
let rest: Vec<i64> = call.rest(engine_state, stack, 1)?;
|
|
||||||
let force: bool = call.has_flag(engine_state, stack, "force")?;
|
let force: bool = call.has_flag(engine_state, stack, "force")?;
|
||||||
let signal: Option<Spanned<i64>> = call.get_flag(engine_state, stack, "signal")?;
|
let signal: Option<Spanned<i64>> = call.get_flag(engine_state, stack, "signal")?;
|
||||||
let quiet: bool = call.has_flag(engine_state, stack, "quiet")?;
|
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 cfg!(unix) {
|
||||||
if let (
|
if let (
|
||||||
true,
|
true,
|
||||||
@ -83,7 +88,7 @@ impl Command for Kill {
|
|||||||
|
|
||||||
let mut cmd = build_kill_command(
|
let mut cmd = build_kill_command(
|
||||||
force,
|
force,
|
||||||
std::iter::once(pid).chain(rest),
|
pids.iter().copied(),
|
||||||
signal.map(|spanned| spanned.item as u32),
|
signal.map(|spanned| spanned.item as u32),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user