Skip to content

fix: complete repeated variadic args - #753

Merged
jdx merged 2 commits into
jdx:mainfrom
Jai-JAP:fix/variadic-completion
Jul 28, 2026
Merged

fix: complete repeated variadic args#753
jdx merged 2 commits into
jdx:mainfrom
Jai-JAP:fix/variadic-completion

Conversation

@Jai-JAP

@Jai-JAP Jai-JAP commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

This fixes completions for repeated variadic positional arguments after the first value has already been entered.

complete-word used the number of parsed positional entries to decide which positional argument to complete next.
That works for normal positionals, but not for variadic args as all values for the repeated args are stored under single positional entry. After typing one value, the arg was incorrectly marked done and fell back to file completions.

The fix checks the parsed value for each positional arg instead. If the arg is variadic and has not reached var_max, it keeps using the same arg's completer. If var_max is reached, it moves on and normal fallback behavior applies.

Also added regression tests for the same.

Related

Validation

  • mise run test -- complete_word_variadic
  • mise run test

Summary by CodeRabbit

  • Bug Fixes

    • Improved CLI completion for variadic arguments.
    • Bounded variadic arguments now stop completing after reaching their maximum allowed items.
    • Completion correctly advances to subsequent arguments or file completion when appropriate.
  • Tests

    • Added regression coverage for repeated and bounded variadic argument completion.
  • Documentation

    • Added an example configuration demonstrating variadic and bounded argument completion.

@Jai-JAP
Jai-JAP force-pushed the fix/variadic-completion branch from c74cc7f to 1dc3293 Compare July 28, 2026 11:39
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Completion now selects the next unfinished positional argument using parsed variadic state, respects var_max, and adds example-backed regression tests for reusable and bounded variadic completions.

Changes

Variadic completion

Layer / File(s) Summary
Select the next completable argument
cli/src/cli/complete_word.rs
Completion scans parsed arguments and continues a variadic argument until its configured maximum before moving to later arguments.
Define and validate variadic behavior
examples/variadic-completion.usage.kdl, cli/tests/complete_word.rs
Adds reusable and bounded variadic commands with foo/bar completions and tests fallback behavior after the bound is reached.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Shell
  participant complete_word
  participant ParseOutput
  participant SpecArg
  Shell->>complete_word: request completion
  complete_word->>ParseOutput: inspect parsed values
  complete_word->>SpecArg: select next completable argument
  SpecArg-->>complete_word: return missing or available variadic argument
  complete_word-->>Shell: return candidates or file completion
Loading

Suggested reviewers: jdx, jambalaya56562

Poem

A rabbit hops through args in a row,
Finding the next place strings may go.
“Foo!” and “bar!” the tokens cheer,
Until the bound says, “No more here.”
Then files appear with a gentle glow.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: fixing completion for repeated variadic positional arguments.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR corrects dynamic completion selection for repeated variadic positional arguments.

  • Selects the next positional completer from parsed argument values rather than the number of parsed entries.
  • Keeps a variadic argument active until its configured var_max is reached.
  • Adds regression coverage and an example specification for bounded and unbounded variadic completion.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
cli/src/cli/complete_word.rs Updates positional completion selection to reuse variadic completers until their maximum value count is reached.
cli/tests/complete_word.rs Adds end-to-end regression tests for repeated unbounded and bounded variadic completions.
examples/variadic-completion.usage.kdl Adds bounded and unbounded variadic command fixtures with dynamic item completions.

Reviews (3): Last reviewed commit: "chore: run render" | Re-trigger Greptile

@Jai-JAP
Jai-JAP force-pushed the fix/variadic-completion branch from 1dc3293 to 7881839 Compare July 28, 2026 11:41
@jdx
jdx merged commit 355e305 into jdx:main Jul 28, 2026
8 checks passed
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Aug 11, 2026
⚠️ **CAUTION: this is a major update, indicating a breaking change!** ⚠️

This MR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [usage](https://github.com/jdx/usage) | tools | major | `3.5.6` → `5.1.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>jdx/usage (usage)</summary>

### [`v5.1.0`](https://github.com/jdx/usage/blob/HEAD/CHANGELOG.md#510---2026-08-09)

[Compare Source](jdx/usage@v5.0.0...v5.1.0)

##### 🚀 Features

- **(spec)** parse usage comments from strings by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;782](jdx/usage#782)

##### 🐛 Bug Fixes

- **(spec)** avoid inferred metadata from included specs by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;786](jdx/usage#786)

##### 🧪 Testing

- **(windows)** make the suite runnable on Windows by [@&#8203;JamBalaya56562](https://github.com/JamBalaya56562) in [#&#8203;771](jdx/usage#771)

##### 📦️ Dependency Updates

- update rust crate rmcp to v3 by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;780](jdx/usage#780)

### [`v5.0.0`](https://github.com/jdx/usage/blob/HEAD/CHANGELOG.md#500---2026-08-02)

[Compare Source](jdx/usage@v4.1.0...v5.0.0)

##### 🚀 Features

- **(cli)** allow overriding the shell program with USAGE\_SHELL\_<SHELL> by [@&#8203;JamBalaya56562](https://github.com/JamBalaya56562) in [#&#8203;767](jdx/usage#767)

##### 🐛 Bug Fixes

- **(cli)** forward parsed args to WSL bash via WSLENV on windows by [@&#8203;JamBalaya56562](https://github.com/JamBalaya56562) in [#&#8203;764](jdx/usage#764)
- **(cli)** let generate markdown write to stdout by [@&#8203;JamBalaya56562](https://github.com/JamBalaya56562) in [#&#8203;766](jdx/usage#766)
- **(complete)** use `type -P` so the CLI-presence guard ignores shell functions by [@&#8203;JamBalaya56562](https://github.com/JamBalaya56562) in [#&#8203;760](jdx/usage#760)
- **(parse)** enforce double\_dash="required" for positional args by [@&#8203;JamBalaya56562](https://github.com/JamBalaya56562) in [#&#8203;762](jdx/usage#762)
- **(windows)** run `run=` scripts with sh when available by [@&#8203;JamBalaya56562](https://github.com/JamBalaya56562) in [#&#8203;765](jdx/usage#765)

##### 🎨 Styling

- fix clippy and deprecation warnings in test and bench targets by [@&#8203;JamBalaya56562](https://github.com/JamBalaya56562) in [#&#8203;763](jdx/usage#763)

### [`v4.1.0`](https://github.com/jdx/usage/blob/HEAD/CHANGELOG.md#410---2026-07-30)

[Compare Source](jdx/usage@v4.0.0...v4.1.0)

##### 🚀 Features

- **(cli)** declare what each usage command does to the world by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;751](jdx/usage#751)
- **(mcp)** serve a usage spec to an agent over stdio by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;746](jdx/usage#746)
- **(spec)** add a top-level `repository` field by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;747](jdx/usage#747)

##### 🐛 Bug Fixes

- **(parse)** keep a re-declared global's aliases on one flag by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;752](jdx/usage#752)
- complete repeated variadic args by [@&#8203;Jai-JAP](https://github.com/Jai-JAP) in [#&#8203;753](jdx/usage#753)

##### New Contributors

- [@&#8203;Jai-JAP](https://github.com/Jai-JAP) made their first contribution in [#&#8203;753](jdx/usage#753)

### [`v4.0.0`](https://github.com/jdx/usage/blob/HEAD/CHANGELOG.md#400---2026-07-25)

[Compare Source](jdx/usage@v3.6.0...v4.0.0)

##### 🚀 Features

- **(spec)** allow effect= on flags and args by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;742](jdx/usage#742)

### [`v3.6.0`](https://github.com/jdx/usage/blob/HEAD/CHANGELOG.md#360---2026-07-25)

[Compare Source](jdx/usage@v3.5.7...v3.6.0)

##### 🚀 Features

- **(spec)** add effect= to declare what a command does to the world by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;739](jdx/usage#739)

##### 🚜 Refactor

- **(spec)** make missed SpecCommand fields a compile error, and fix the four that were already missed by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;740](jdx/usage#740)

### [`v3.5.7`](https://github.com/jdx/usage/blob/HEAD/CHANGELOG.md#357---2026-07-25)

[Compare Source](jdx/usage@v3.5.6...v3.5.7)

##### 🐛 Bug Fixes

- **(parse)** don't leak the mounting CLI's flags into mounted commands; scan past non-global flags by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;738](jdx/usage#738)

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4yODguMCIsInVwZGF0ZWRJblZlciI6IjQzLjI4OC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiLCJhdXRvbWF0aW9uOmJvdC1hdXRob3JlZCIsImRlcGVuZGVuY3ktdHlwZTo6bWFqb3IiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants