Skip to content

Commit

Permalink
Merge pull request #66 from rsteube/fix-persistent
Browse files Browse the repository at this point in the history
fix persisentflags
  • Loading branch information
rsteube authored Mar 25, 2023
2 parents 2d5c60e + c72b928 commit f5e24fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/carapace_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,24 @@ impl Generator for Spec {
}

fn generate(&self, cmd: &clap::Command, buf: &mut dyn std::io::Write) {
let command = command_for(cmd);
let command = command_for(cmd, true);
let serialized = serde_yaml::to_string(&command).unwrap();
buf.write_all(serialized.as_bytes())
.expect("Failed to write to generated file");
}
}

fn command_for(cmd: &clap::Command) -> Command {
fn command_for(cmd: &clap::Command, root: bool) -> Command {
Command {
name: cmd.get_name().to_owned(),
aliases: cmd.get_all_aliases().map(String::from).collect(),
description: cmd.get_about().unwrap_or_default().to_string(),
flags: flags_for(cmd, false),
persistentflags: flags_for(cmd, true),
persistentflags: if let true = root {
flags_for(cmd, true)
} else {
Default::default()
},
completion: Completion {
flag: flag_completions_for(cmd),
positional: positional_completion_for(cmd),
Expand All @@ -77,7 +81,7 @@ fn command_for(cmd: &clap::Command) -> Command {
commands: cmd
.get_subcommands()
.filter(|c| !c.is_hide_set())
.map(command_for)
.map(|c| command_for(c, false))
.collect(),
..Default::default()
}
Expand Down
2 changes: 0 additions & 2 deletions tests/snapshots/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ commands:
description: Subcommand
flags:
-d*: ''
persistentflags:
-c: ''

0 comments on commit f5e24fb

Please sign in to comment.