feat: add --generate-completion for shell tab completion
- Add clap_complete dependency for bash/zsh/fish/elvish/powershell - Add --generate-completion <shell> flag that prints completion script to stdout - profile.bash sources completions via command keep --generate-completion bash - @ and @@ aliases get completions via wrapper functions that delegate to _keep - README updated with Shell Completion section
This commit is contained in:
@@ -2,6 +2,7 @@ use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
|
||||
use clap::*;
|
||||
use clap_complete::Shell;
|
||||
|
||||
/// Main struct for command-line arguments, parsed via Clap.
|
||||
#[derive(Parser, Debug, Clone)]
|
||||
@@ -68,6 +69,10 @@ pub struct ModeArgs {
|
||||
#[arg(help("Generate default configuration and output to stdout"))]
|
||||
pub generate_config: bool,
|
||||
|
||||
#[arg(help_heading("Mode Options"), long, conflicts_with_all(["save", "get", "diff", "list", "delete", "info", "status", "server", "generate_config"]))]
|
||||
#[arg(help("Generate shell completion script (bash, zsh, fish, elvish, powershell)"))]
|
||||
pub generate_completion: Option<Shell>,
|
||||
|
||||
#[arg(help_heading("Server Options"), long, env("KEEP_SERVER_ADDRESS"))]
|
||||
#[arg(help("Server address to bind to"))]
|
||||
pub server_address: Option<String>,
|
||||
|
||||
@@ -28,6 +28,12 @@ fn main() -> Result<(), Error> {
|
||||
cmd.error(ErrorKind::ValueValidation, e).exit();
|
||||
}
|
||||
|
||||
// Handle --generate-completion early (prints to stdout and exits)
|
||||
if let Some(shell) = args.mode.generate_completion {
|
||||
clap_complete::generate(shell, &mut Args::command(), "keep", &mut std::io::stdout());
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
let start = Instant::now();
|
||||
let mut builder = env_logger::Builder::new();
|
||||
let show_module = args.options.verbose >= 2;
|
||||
|
||||
Reference in New Issue
Block a user