shell competion for sub-commands using derive OM #3657
-
Given a #[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
struct Args {
#[clap(subcommand)]
command: Cmd,
}
#[derive(Subcommand, Debug)]
enum Cmd {
/// Initializes a directory as a backclone repository.
Init(InitCtx),
/// Adds to the repository.
Add(AddCtx),
/// Validates links to the repository of select definitions.
Check(DeployCtx),
/// Deploys links to the repository according to select definitions in the manifest.
Deploy(DeployCtx),
/// Validates a template expression and enumerates possible results.
Verify(VerCtx),
}
#[derive(Parser, Debug)]
struct InitCtx {
/// Path to the directory to initialize as a repository
#[clap(default_value = "./", value_hint = ValueHint::DirPath)]
repository_path: PathBuf,
}
[...]
fn main() {
let res = match Args::parse().command {
Cmd::Init(ctx) => init(ctx),
Cmd::Add(ctx) => add(ctx),
Cmd::Check(ctx) => check(ctx),
Cmd::Deploy(ctx) => deploy(ctx),
Cmd::Verify(ctx) => verify(ctx),
};
if let Err(e) = res {
println!("{}", e);
}
} I which to enable autocompletion for sub-commands using clap_complete. How do I go about it? The docs explain how I may enable shell completion given a |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Derive Reference's tips calls attention to how to access a
This is important for other reasons, like
|
Beta Was this translation helpful? Give feedback.
Derive Reference's tips calls attention to how to access a
Command
:This is important for other reasons, like
clap_complete
also comes with a derive example, https://github.com/clap-rs/clap/blob/master/clap_complete/examples/value_hints_derive.rs.