soroban_cli/commands/
completion.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use clap::{arg, CommandFactory, Parser};
use clap_complete::{generate, Shell};
use std::io;

use crate::commands::Root;

pub const LONG_ABOUT: &str = "\
Print shell completion code for the specified shell

Ensure the completion package for your shell is installed, e.g. bash-completion for bash.

To enable autocomplete in the current bash shell, run: `source <(stellar completion --shell bash)`

To enable autocomplete permanently, run: `echo \"source <(stellar completion --shell bash)\" >> ~/.bashrc`
";

#[derive(Parser, Debug, Clone)]
#[group(skip)]
pub struct Cmd {
    /// The shell type
    #[arg(long, value_enum)]
    shell: Shell,
}

impl Cmd {
    pub fn run(&self) {
        let cmd = &mut Root::command();
        generate(self.shell, cmd, "stellar", &mut io::stdout());
    }
}