mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 06:44:16 +00:00
feat(clap_complete_fig): Add subcommand aliases support
This commit is contained in:
parent
fb39216caf
commit
a404ab8680
2 changed files with 30 additions and 8 deletions
|
@ -52,13 +52,35 @@ fn gen_fig_inner(
|
|||
buffer.push_str(&format!("{:indent$}subcommands: [\n", "", indent = indent));
|
||||
// generate subcommands
|
||||
for subcommand in cmd.get_subcommands() {
|
||||
buffer.push_str(&format!(
|
||||
"{:indent$}{{\n{:indent$} name: \"{}\",\n",
|
||||
"",
|
||||
"",
|
||||
subcommand.get_name(),
|
||||
indent = indent + 2
|
||||
));
|
||||
let mut aliases: Vec<&str> = subcommand.get_all_aliases().collect();
|
||||
if !aliases.is_empty() {
|
||||
aliases.insert(0, subcommand.get_name());
|
||||
|
||||
buffer.push_str(&format!(
|
||||
"{:indent$}{{\n{:indent$} name: [",
|
||||
"",
|
||||
"",
|
||||
indent = indent + 2
|
||||
));
|
||||
|
||||
buffer.push_str(
|
||||
&aliases
|
||||
.iter()
|
||||
.map(|name| format!("\"{}\"", name))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", "),
|
||||
);
|
||||
|
||||
buffer.push_str("],\n");
|
||||
} else {
|
||||
buffer.push_str(&format!(
|
||||
"{:indent$}{{\n{:indent$} name: \"{}\",\n",
|
||||
"",
|
||||
"",
|
||||
subcommand.get_name(),
|
||||
indent = indent + 2
|
||||
));
|
||||
}
|
||||
|
||||
if let Some(data) = subcommand.get_about() {
|
||||
buffer.push_str(&format!(
|
||||
|
|
|
@ -53,7 +53,7 @@ const completion: Fig.Spec = {
|
|||
},
|
||||
},
|
||||
{
|
||||
name: "some-cmd-with-hyphens",
|
||||
name: ["some-cmd-with-hyphens", "hyphen"],
|
||||
options: [
|
||||
{
|
||||
name: ["-h", "--help"],
|
||||
|
|
Loading…
Reference in a new issue