cardanowall_cli/commands/
completion.rs1use clap::{Args, CommandFactory, ValueEnum};
7use clap_complete::{generate, Shell};
8
9use crate::cli::Cli;
10use crate::util::CliError;
11
12#[derive(Debug, Args)]
14pub struct CompletionArgs {
15 #[arg(value_enum)]
17 pub shell: CompletionShell,
18}
19
20#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
23pub enum CompletionShell {
24 Bash,
26 Zsh,
28 Fish,
30 Powershell,
32}
33
34impl From<CompletionShell> for Shell {
35 fn from(value: CompletionShell) -> Self {
36 match value {
37 CompletionShell::Bash => Shell::Bash,
38 CompletionShell::Zsh => Shell::Zsh,
39 CompletionShell::Fish => Shell::Fish,
40 CompletionShell::Powershell => Shell::PowerShell,
41 }
42 }
43}
44
45pub fn run(args: CompletionArgs) -> Result<(), CliError> {
51 let mut cmd = Cli::command();
52 let bin_name = cmd.get_name().to_string();
53 generate(
54 Shell::from(args.shell),
55 &mut cmd,
56 bin_name,
57 &mut std::io::stdout(),
58 );
59 Ok(())
60}