mirror of
https://github.com/qwjyh/xdbm
synced 2025-06-26 17:59:20 +09:00
add shell completion script generation
This commit is contained in:
parent
f5fe3d6580
commit
8396b8c97d
5 changed files with 33 additions and 1 deletions
|
@ -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
12
src/cmd_completion.rs
Normal 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(())
|
||||
}
|
|
@ -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(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue