cli: add 'completions <SHELL>' subcommand via clap_complete

This commit is contained in:
adlee-was-taken
2026-05-01 18:13:17 -04:00
parent e452d8df02
commit 6cbd011705
4 changed files with 55 additions and 1 deletions

View File

@@ -8,7 +8,8 @@ mod session;
use std::path::PathBuf;
use anyhow::{bail, Context, Result};
use clap::{Parser, Subcommand};
use clap::{CommandFactory, Parser, Subcommand};
use clap_complete::{generate, Shell};
#[derive(Parser)]
#[command(
@@ -163,6 +164,13 @@ enum Commands {
/// Lock the vault (no-op in CLI; present for UX parity with the extension).
Lock,
/// Emit a shell completion script for the given shell.
/// Pipe to your shell's completion file (e.g. `> /etc/bash_completion.d/relicario`).
Completions {
#[arg(value_enum)]
shell: Shell,
},
}
#[derive(Subcommand)]
@@ -354,6 +362,11 @@ fn main() -> Result<()> {
Commands::Status => cmd_status(),
Commands::Device { action } => cmd_device(action),
Commands::Lock => { eprintln!("no cached session to lock"); Ok(()) }
Commands::Completions { shell } => {
let mut cmd = Cli::command();
generate(shell, &mut cmd, "relicario", &mut std::io::stdout());
Ok(())
}
}
}