Approved · 0 retained findingsclap-rs/clap#6400
fix(clap_complete_nushell): disable generating last arguments
Input
PR author’s description
<!--
Thanks for helping out!
Please link the appropriate issue from your PR.
If you don't have an issue, we'd recommend starting with one first so the PR can focus on the
implementation (unless its an obvious bug…
PR diff
Current GitHub diff ↗+ clap::Command::new("last-hint").args([+ clap::Arg::new("first")+ .value_parser(["bash", "fish", "zsh"])+ .required(true),
Browse 7 changed files
clap_complete_nushell/examples/test.rs+9 −0
@@ -95,6 +95,15 @@ fn cli() -> clap::Command { ]), clap::Command::new("last") .args([clap::Arg::new("first"), clap::Arg::new("free").last(true)]),+ clap::Command::new("last-hint").args([+ clap::Arg::new("first")+ .value_parser(["bash", "fish", "zsh"])+ .required(true),+ clap::Arg::new("free")+ .value_parser(["nushell", "powershell"])+ .required(true)+ .last(true),+ ]), clap::Command::new("alias").args([ clap::Arg::new("flag") .short('f')
clap_complete_nushell/tests/snapshots/last_args.nu+73 −0
@@ -0,0 +1,73 @@+module completions {++ export extern my-app [+ --help(-h) # Print help+ ]++ export extern "my-app single" [+ --help(-h) # Print help+ arg: string+ ]++ export extern "my-app multiple" [+ --help(-h) # Print help+ ...args: string+ ]++ def "nu-complete my-app choice arg" [] {+ [ "bash" "zsh" "fish" ]+ }++ export extern "my-app choice" [+ --help(-h) # Print help+ arg: string@"nu-complete my-app choice arg"+ ]++ def "nu-complete my-app multiple-choice args" [] {+ [ "bash" "zsh" "fish" ]+ }++ export extern "my-app multiple-choice" [+ --help(-h) # Print help+ ...args: string@"nu-complete my-app multiple-choice args"+ ]++ export extern "my-app any-path" [+ --help(-h) # Print help+ arg: path+ ]++ export extern "my-app multiple-any-path" [+ --help(-h) # Print help+ ...args: path+ ]++ # Print this message or the help of the given subcommand(s)+ export extern "my-app help" [+ ]++ export extern "my-app help single" [+ ]++ export extern "my-app help multiple" [+ ]++ export extern "my-app help choice" [+ ]++ export extern "my-app help multiple-choice" [+ ]++ export extern "my-app help any-path" [+ ]++ export extern "my-app help multiple-any-path" [+ ]++ # Print this message or the help of the given subcommand(s)+ export extern "my-app help help" [+ ]++}++export use completions *
clap_complete_nushell/tests/common.rs+59 −0
@@ -267,6 +267,65 @@ pub(crate) fn value_hint_command(name: &'static str) -> Command { ) } +pub(crate) fn last_args_command(name: &'static str) -> Command {+ Command::new(name).subcommands([+ Command::new("single")+ .arg(Arg::new("arg").required(true))+ .arg(Arg::new("last_arg").required(true).last(true)),+ Command::new("multiple")+ .arg(Arg::new("args").num_args(1..))+ .arg(Arg::new("last_args").num_args(1..).last(true)),+ Command::new("choice")+ .arg(+ Arg::new("arg")+ .required(true)+ .value_parser(["bash", "zsh", "fish"]),+ )+ .arg(+ Arg::new("last_arg")+ .required(true)+ .value_parser(["nushell", "powershell"])+ .last(true),+ ),+ Command::new("multiple-choice")+ .arg(+ Arg::new("args")+ .num_args(1..)+ .value_parser(["bash", "zsh", "fish"]),+ )+ .arg(+ Arg::new("last_args")+ .num_args(1..)+ .value_parser(["nushell", "powershell"])+ .last(true),+ ),+ Command::new("any-path")+ .arg(+ Arg::new("arg")+ .required(true)+ .value_hint(ValueHint::AnyPath),+ )+ .arg(+ Arg::new("last_arg")+ .required(true)+ .value_hint(ValueHint::AnyPath)+ .last(true),+ ),+ Command::new("multiple-any-path")+ .arg(+ Arg::new("args")+ .num_args(1..)+ .value_hint(ValueHint::AnyPath),+ )+ .arg(+ Arg::new("last_args")+ .num_args(1..)+ .value_hint(ValueHint::AnyPath)+ .last(true),+ ),+ ])+}+ pub(crate) fn assert_matches( expected: impl IntoData, generator: impl clap_complete::Generator,
Outcome
Why this verdict
approve — No checked defect was established by the available proof adapters.
Lens advisories (not part of the checked findings):
- complexity_maintainability: The diff adds two patterns that skip processing (continue) whenever a clap argument is marked as last(). This creates duplication of last-handling logic across core generator code (generate_completion and append_argument) and exposes fragility if the skip logic or its assumption about nushell support changes.
Lens coverage: 6 delivered
The recorded observations did not become verified findings.
Evidence and perspectives
Observation · Complexity maintainabilityThe diff adds two patterns that skip processing (continue) whenever a clap argument is marked as last(). This creates duplication of last-handling logic across core generator code (generate_completion and append_argument) and exposes fragility if the skip logic or its assumption about nushell support changes.
Recorded location clap_complete_nushell/src/lib.rs:208
Observation · Test strategyThe 'last-hint' subcommand is added in the code change but lacks dedicated behavioral tests in the diff; the new last-hint logic in lib.rs and its nushell completions snapshot should be verified by test cases.
Recorded location clap_complete_nushell/src/lib.rs:133