hivectl: shell completions verb + ship zsh/bash/fish completions (#1764)
Add a 'hivectl completions <shell>' subcommand (clap_complete) that prints a completion script for bash/zsh/fish/elvish/powershell, generated from hivectl's own clap command tree so it never drifts from the real verbs/flags. The package build installs the bash/zsh/fish scripts via installShellFiles, so an operator gets working completion automatically once hivectl is on their profile with shell completion enabled. Regenerated docs/tools/hivectl-cli.md for the new verb.
This commit is contained in:
parent
f5003fd1bb
commit
c7612dcf2b
6 changed files with 73 additions and 1 deletions
|
|
@ -157,6 +157,18 @@ enum Cmd {
|
|||
/// hand-maintained command list to drift out of date.
|
||||
#[command(hide = true)]
|
||||
MarkdownDocs,
|
||||
/// Generate a shell completion script for `hivectl` and print it to
|
||||
/// stdout.
|
||||
///
|
||||
/// Pipe it into your shell's completion path — e.g. for zsh:
|
||||
/// `hivectl completions zsh > ~/.zsh/completions/_hivectl` (with that
|
||||
/// dir on `$fpath`). The hyperhive NixOS module installs the zsh script
|
||||
/// system-wide automatically, so this is mainly for ad-hoc / other-shell
|
||||
/// use. Supports bash, zsh, fish, elvish, and powershell.
|
||||
Completions {
|
||||
/// Shell to emit completions for.
|
||||
shell: clap_complete::Shell,
|
||||
},
|
||||
}
|
||||
|
||||
/// Shared scope flags for `hivectl stop` / `hivectl start`. With no flag
|
||||
|
|
@ -441,9 +453,22 @@ async fn main() -> Result<()> {
|
|||
print!("{}", clap_markdown::help_markdown::<Cli>());
|
||||
Ok(())
|
||||
}
|
||||
Cmd::Completions { shell } => {
|
||||
generate_completions(shell);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Emit a shell completion script for `hivectl` to stdout. Walks the clap
|
||||
/// command tree (the single source of truth — same tree `markdown-docs`
|
||||
/// renders) so completions never drift from the actual verbs/flags.
|
||||
fn generate_completions(shell: clap_complete::Shell) {
|
||||
use clap::CommandFactory as _;
|
||||
let mut cmd = Cli::command();
|
||||
clap_complete::generate(shell, &mut cmd, "hivectl", &mut std::io::stdout());
|
||||
}
|
||||
|
||||
/// True when `name` matches an existing hyperhive agent — i.e. it has a
|
||||
/// persistent state dir under `/var/lib/hyperhive/agents/`. We use the
|
||||
/// state dir (not the live container list) so kept-state tombstones
|
||||
|
|
|
|||
Loading…
Reference in a new issue