Skip to content

Bug: Bash/PowerShell completions don't show parent flags for commands with subcommands #463

@TabishB

Description

@TabishB

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
fi

Files to Modify

  • src/core/completions/generators/bash-generator.ts
  • src/core/completions/generators/powershell-generator.ts

Related

Discovered during review of PR #401 (multi-shell completion support).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions