-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
Summary
When a command has both flags AND subcommands, Bash and PowerShell generators only offer subcommands at the parent level, never the parent flags. Fish handles this correctly.
Example
For a command structure like:
openspec config
├── FLAGS: --scope, --json
└── SUBCOMMANDS: set, get, list
Expected behavior
$ openspec config --<TAB>
--scope --json set get list
Actual behavior
$ openspec config --<TAB>
set get list # Parent flags missing!
Affected Shells
| Shell | Works? |
|---|---|
| Fish | ✅ Yes |
| Bash | ❌ No |
| PowerShell | ❌ No |
Root Cause
In bash-generator.ts (generateCommandCase method), when subcommands exist:
if (cmd.subcommands && cmd.subcommands.length > 0) {
lines.push(`${indent}if [[ $cword -eq 2 ]]; then`);
lines.push(`${indent} local subcommands="..."`);
lines.push(`${indent} COMPREPLY=(...)`);
lines.push(`${indent} return 0`); // ← Exits immediately, never offers parent flags
lines.push(`${indent}fi`);PowerShell has the same pattern.
Fish correctly handles this at line 1216-1219:
// Add flags for parent command
for (const flag of cmd.flags) {
lines.push(...this.generateFlagCompletion(flag, `__fish_openspec_using_subcommand ${cmd.name}`));
}Suggested Fix
Check if user is typing a flag ($cur starts with -) and offer parent flags in that case:
if [[ $cword -eq 2 ]]; then
if [[ "$cur" == -* ]]; then
# Offer parent command flags
local flags="--scope --json"
COMPREPLY=($(compgen -W "$flags" -- "$cur"))
else
# Offer subcommands
local subcommands="set get list"
COMPREPLY=($(compgen -W "$subcommands" -- "$cur"))
fi
return 0
fiFiles to Modify
src/core/completions/generators/bash-generator.tssrc/core/completions/generators/powershell-generator.ts
Related
Discovered during review of PR #401 (multi-shell completion support).
Metadata
Metadata
Assignees
Labels
No labels