Skip to content

fix(completion): rely on usage#649 for global flags, keep -r/-S promotion#10176

Merged
jdx merged 1 commit into
jdx:mainfrom
JamBalaya56562:completion-usage-649-global-flags
Jun 1, 2026
Merged

fix(completion): rely on usage#649 for global flags, keep -r/-S promotion#10176
jdx merged 1 commit into
jdx:mainfrom
JamBalaya56562:completion-usage-649-global-flags

Conversation

@JamBalaya56562

@JamBalaya56562 JamBalaya56562 commented May 31, 2026

Copy link
Copy Markdown
Contributor

Problem

Completion fails when a run/tasks run flag (or a root global flag) precedes the task, e.g.:

mise -C <dir> run <task> -- <TAB>     # was: Invalid choice for arg profile: -C
mise run -r <task> -- <TAB>           # unexpected word: <task>

The run/tasks run subcommands redeclare several root globals as their own non-global flags. When the usage parser descends into the mounted task spec it keeps only inherited globals, so a flag placed before the task was dropped and mis-parsed during completion (#10069). #10153 worked around this by promoting every colliding flag (-C/-j/-q/-r/-S) to global in the completion spec.

What changed

jdx/usage#649 (released in usage 3.4.0, see jdx/usage#652) fixes the common case in the parser: an inherited global redeclared as non-global is now preserved together with all its aliases. That covers -C/--cd, -j/--jobs and -q/--quiet, whose short is a root global short, so they no longer need the workaround.

It cannot cover -r/--raw and -S/--silent: their root globals are long-only (--raw/--silent have no short), and the -r/-S shorts exist only on the non-global run redeclarations, which the parser drops. So this PR narrows the old "promote everything" closure to just these orphan-short flags (long matches a root global, short does not).

Note: This PR is rebased on top of #10181, which already bumped usage (and usage-lib) to 3.4.0 in the tree, regenerated mise.usage.kdl in the 3.4.0 serialization format, and updated the zsh completions/e2e for the new tab-separated display\tinsert output. #10181 did not touch src/cli/usage.rs, so the broad #10153 promotion workaround was still in place — this PR is the follow-up cleanup that narrows it now that 3.4.0 is the baseline.

  • src/cli/usage.rs: replace the broad promote with promote_orphan_shorts, and set min_usage_version to "3.4" so usage CLIs older than the #649 fix warn to upgrade instead of silently re-triggering mise completion bug with `-C` and task argument `choices` #10069.
  • mise.usage.kdl: -C/-j/-q drop global=#true (now handled upstream by #649); -r/-S keep it. min_usage_version is bumped to 3.4. (Regenerated on top of fix(task): bump usage for completions #10181, so the surrounding spec is already in the 3.4.0 format — this PR's diff is limited to the global attribute and the version line.)
  • e2e/tasks/test_task_completion_global_cd: add -r/-S coverage over the run and tasks run paths, using the tab-separated completion output introduced in fix(task): bump usage for completions #10181.

Verification

Locally with usage 3.4.0, completion returns the task's choices for -C/-j/-q/-r/-S before the mounted task:

mise -C . run sample:run -- ''      -> alpha beta gamma
mise run -r sample:run -- ''        -> alpha beta gamma
mise run -S sample:run -- ''        -> alpha beta gamma
mise tasks run -r sample:run -- ''  -> alpha beta gamma

cargo fmt, shfmt, shellcheck are clean. Shell completions, man pages, fig, and docs are unaffected (the global attribute is not rendered into those artifacts).

Out of scope

Purely-run flags with no root-global counterpart (-f/-n/-o) remain a separate pre-existing completion limitation when placed before the mounted task; not introduced or changed by this PR.

Summary by CodeRabbit

  • Bug Fixes

    • Improved command-line completion for run and tasks run, including edge cases where global flags appear before the command and when short-form flags are redeclared; orphan short flags (-r/--raw, -S/--silent) are now correctly recognized and suggested.
  • Chores

    • Raised minimum CLI usage-spec version requirement for improved completion behavior.

@coderabbitai

coderabbitai Bot commented May 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2dfc86df-6f68-434e-8ccb-e5d702d311a8

📥 Commits

Reviewing files that changed from the base of the PR and between c99ea84 and e70c600.

📒 Files selected for processing (3)
  • e2e/tasks/test_task_completion_global_cd
  • mise.usage.kdl
  • src/cli/usage.rs
💤 Files with no reviewable changes (1)
  • mise.usage.kdl
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/cli/usage.rs
  • e2e/tasks/test_task_completion_global_cd

📝 Walkthrough

Walkthrough

Selective completion-spec promotion was implemented: only mounted flags whose long matches a root global and that expose short aliases absent from the root global are marked global. The usage spec minimum version was raised to 3.4, global attributes removed from run command flags, and e2e tests extended to cover orphan-short flags (-r, -S) before run and tasks run.

Changes

Orphan short flag promotion for completion specs

Layer / File(s) Summary
Usage specification version and global flag scoping
mise.usage.kdl
Minimum usage version updated from 2.11 to 3.4. Removed global=#true`` from -C/--cd, `-j/--jobs`, and `-q/--quiet` in both `cmd run` usage-spec blocks.
Orphan short promotion implementation
src/cli/usage.rs
Added promote_orphan_shorts closure that promotes mounted flags to global only when the mounted flag's long matches a root global and the mounted flag exposes short aliases not present on the root global. Applied to run and nested tasks run mounts and updated emitted min_usage_version string to 3.4.
E2E completion test for orphan short global flags
e2e/tasks/test_task_completion_global_cd
Expanded test header and added zsh completion assertions verifying orphan-short flags -r/--raw and -S/--silent remain recognized when placed before the mounted task for both mise run and mise tasks run, while positional choices (alpha, beta, gamma) still complete.

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • jdx/mise#10181: Related change aligning completion e2e expectations and usage version bump to 3.4.

"🐰
I hopped through flags both short and long,
Promoted the orphans where they belong,
Bumped the version, tuned the spec's song,
Tests now hum the completion throng,
Short flags and choices all along."

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing completion handling for global flags by relying on an upstream usage fix while keeping promotion for orphan short flags.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@greptile-apps

greptile-apps Bot commented May 31, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR narrows the completion-spec workaround for run/tasks run flag promotion: instead of promoting all five colliding flags to global, it now promotes only the two "orphan-short" flags (-r/-S) whose root globals are long-only. The remaining three are handled correctly by the upstream jdx/usage#649 parser fix shipped in usage 3.4.

  • src/cli/usage.rs: The broad promote closure is replaced by promote_orphan_shorts, which marks a flag global only when its long matches a root global but its short does not appear on that root global; min_usage_version is bumped to \"3.4\".
  • mise.usage.kdl: global=#true is removed from -C/-j/-q in both run and tasks run; -r/-S keep it; min_usage_version updated in sync.
  • e2e/tasks/test_task_completion_global_cd: Four new assertions verify -r and -S behave correctly when placed before a mounted task on both run and tasks run paths.

Confidence Score: 5/5

Safe to merge — a well-scoped narrowing of an existing workaround with consistent updates to both the static KDL and runtime code.

The promote_orphan_shorts logic correctly targets only -r/-S, the min_usage_version bump guards against older parsers, and the new e2e assertions directly exercise the fixed paths.

No files require special attention.

Important Files Changed

Filename Overview
src/cli/usage.rs Replaces broad promote-all logic with promote_orphan_shorts; min_usage_version bumped to 3.4
mise.usage.kdl Removes global=#true from -C/-j/-q (now handled upstream); -r/-S retain global=#true; min_usage_version updated
e2e/tasks/test_task_completion_global_cd Adds four assertions covering -r and -S on both run and tasks run paths

Reviews (2): Last reviewed commit: "fix(completion): rely on usage#649 for g..." | Re-trigger Greptile

…tion

The `run`/`tasks run` subcommands redeclare several root globals as their own
non-global flags. When the usage parser descends into the mounted task spec it
keeps only inherited globals, so a flag placed before the task used to be
dropped and mis-parsed during completion (mise#10069). mise#10153 worked around
this by promoting every colliding flag (-C/-j/-q/-r/-S) to global in the
completion spec.

usage#649 (in usage 3.4.0) fixes the common case in the parser: an inherited
global redeclared as non-global is now preserved together with all its aliases.
That covers -C/--cd, -j/--jobs and -q/--quiet, whose short is itself a root
global short, so they no longer need the workaround.

It cannot cover -r/--raw and -S/--silent: their root globals are long-only
(--raw/--silent have no short), and the -r/-S shorts exist only on the
non-global `run` redeclarations, which the parser drops. So narrow the old
"promote everything" closure to just these orphan-short flags (long matches a
root global, short does not).

- src/cli/usage.rs: replace the broad promote with promote_orphan_shorts, and
  set min_usage_version to "3.4" so usage CLIs older than the #649 fix warn to
  upgrade instead of silently re-triggering mise#10069.
- mise.usage.kdl: -C/-j/-q drop global=#true (now handled upstream); -r/-S keep
  it. usage-lib itself is left at 3 -- spec generation is unaffected by #649 and
  the runtime requirement is carried by min_usage_version (the e2e installs
  usage latest).
- e2e: add -r/-S coverage over the run and tasks-run paths.

Verified locally with usage 3.4.0: completion returns the task's choices for
-C/-j/-q/-r/-S before the mounted task. Purely-run flags with no root-global
counterpart (-f/-n/-o) remain a separate pre-existing completion limitation,
unchanged here.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@JamBalaya56562 JamBalaya56562 force-pushed the completion-usage-649-global-flags branch from c99ea84 to e70c600 Compare June 1, 2026 00:19
@jdx jdx merged commit 9522d04 into jdx:main Jun 1, 2026
33 checks passed
@JamBalaya56562 JamBalaya56562 deleted the completion-usage-649-global-flags branch June 1, 2026 00:46
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