Menu ▾ ▴

#16 [Feature]: Generate shell completion scripts

open
nobody
2026-09-30
2026-09-11
Anonymous
No

Originally created by: thomijasir
Originally owned by: thomijasir

Feature description

Generate completion scripts for supported shells from the Dopbase command definition.

Current behavior

The CLI has command help but does not provide shell completion output.

Why we need this

The command tree now includes server, client, project, environment, secret, token, backup, and administration operations. Completion reduces typing mistakes and makes flags easier to discover.

Proposed CLI interface

  • dopbase completion bash
  • dopbase completion zsh
  • dopbase completion fish
  • dopbase completion powershell
  • dopbase completion elvish

Expected behavior

  • Write the selected completion script to stdout.
  • Return a non-zero exit code for an unsupported shell.
  • Keep generation independent of client configuration, login state, and network access.
  • Use the command definitions as the source so new commands and flags appear automatically.

Security and compatibility

  • Completion generation must not read sessions, tokens, cache files, or secret data.
  • Errors and diagnostics go to stderr so stdout remains a valid script.

Out of scope

  • Installing or editing shell profile files.
  • Completing server-side resource names. Track that separately.

Acceptance criteria

  • [ ] Each supported shell receives a non-empty completion script.
  • [ ] Generated scripts include top-level commands, nested commands, and global flags.
  • [ ] The command works without a server or login.
  • [ ] --json is rejected because stdout is reserved for the script.
  • [ ] Help text explains how to load the generated script.

Test scenarios

  • Add parser tests and completion snapshots under app/tests/cli/.
  • Check representative nested commands and flags for every supported shell.

Documentation

Add installation examples for each supported shell without modifying user profile files automatically.

Dependencies

Add the completion library that matches the current Clap version.

Related

Tickets: #25

Discussion

  • Anonymous

    Anonymous - 2026-09-11
     
  • Anonymous

    Anonymous - 2026-09-30

    Originally posted by: rudratoshs

    Hi @thomijasir — I'd be glad to take this one off your plate if outside PRs are welcome. I noticed most issues here are self-assigned, so I wanted to check before opening anything rather than surprise you with a PR you'd have to redirect.

    Here's exactly how I'd implement it, to match the spec above and keep the surface minimal:

    Approach

    • Add clap_complete (tracking the current clap 4 line) as the only new dependency.
    • Add a Completion { shell: clap_complete::Shell } variant to Command. clap_complete::Shell is precisely bash/zsh/fish/powershell/elvish — the five listed — so an unsupported value is rejected by the parser itself with a non-zero exit, satisfying that criterion without custom validation.
    • Generate with clap_complete::generate(shell, &mut Cli::command(), "dopbase", &mut io::stdout()), sourced from the derived command tree so new commands and flags appear automatically.
    • Generation reads no session, token, cache, or network — only the static command definition. Diagnostics go to stderr so stdout stays a valid script.
    • Reject --json completion … with a clear stderr message and non-zero exit, since stdout is reserved for the script.
    • after_help on the subcommand documents how to load each shell's output (e.g. source <(dopbase completion bash)) without editing any profile files.

    Tests (under app/tests/cli/)

    • Parser tests: completion <shell> parses for each supported shell; an unknown shell errors.
    • Script asserts: each shell yields a non-empty script containing a top-level command, a nested command (e.g. secret get), and a global flag (--json / --server).
    • --json completion bash is rejected with the reserved-stdout error.

    That keeps it to one dependency, one subcommand, and no new resolution rules — and leaves resource-aware completion (#25) to sit cleanly on top via a hidden entry point later.

    Want me to open the PR on this, or would you rather keep it? Happy either way.

     
  • Anonymous

    Anonymous - 2026-09-30

    Originally posted by: thomijasir

    Thanks for your input, @rudratoshs! This feature isn’t a priority right now, i’d like to focus on the core functionality and keep the CLI simple (trying to simplify dopbase <command>).

    If you’d like to contribute, let’s start with something small. currently the app doesn't have a restart command yet, so adding dopbase server restart would be a great place to start.

    Thanks

     

Log in to post a comment.