add shell completion script generation

This commit is contained in:
qwjyh 2024-03-17 04:08:47 +09:00
parent f5fe3d6580
commit 8396b8c97d
5 changed files with 33 additions and 1 deletions

View file

@ -55,6 +55,11 @@ pub(crate) enum Commands {
/// Check config files.
Check {},
/// Generate completion script.
Completion {
shell: clap_complete::Shell,
}
}
#[derive(Args, Debug)]

12
src/cmd_completion.rs Normal file
View file

@ -0,0 +1,12 @@
use crate::cmd_args::Cli;
use std::io;
use anyhow::Result;
use clap::CommandFactory;
use clap_complete::Shell;
pub(crate) fn cmd_completion(shell: Shell) -> Result<()> {
let mut cmd = Cli::command();
clap_complete::generate(shell, &mut cmd, "xdbm", &mut io::stdout());
Ok(())
}

View file

@ -31,6 +31,7 @@ mod cmd_backup;
mod cmd_init;
mod cmd_storage;
mod cmd_sync;
mod cmd_completion;
mod devices;
mod inquire_filepath_completer;
mod storages;
@ -122,6 +123,9 @@ fn main() -> Result<()> {
} => cmd_backup::cmd_backup_done(name, exit_status, log, repo, &config_dir)?,
}
}
Commands::Completion { shell } => {
cmd_completion::cmd_completion(shell)?
}
}
full_status(&Repository::open(&config_dir)?)?;
Ok(())