cli: add 'completions <SHELL>' subcommand via clap_complete
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user