Skip to content

Commit

Permalink
Merge pull request #64 from rsteube/persistent-flags
Browse files Browse the repository at this point in the history
support persistent flags
  • Loading branch information
rsteube authored Mar 25, 2023
2 parents e88abf4 + c0e1a18 commit 2d5c60e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/carapace_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ fn command_for(cmd: &clap::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),
flags: flags_for(cmd, false),
persistentflags: flags_for(cmd, true),
completion: Completion {
flag: flag_completions_for(cmd),
positional: positional_completion_for(cmd),
Expand All @@ -82,13 +83,14 @@ fn command_for(cmd: &clap::Command) -> Command {
}
}

fn flags_for(cmd: &clap::Command) -> Map<String, String> {
fn flags_for(cmd: &clap::Command, persistent: bool) -> Map<String, String> {
let mut m = Map::new();

let mut arguments = cmd
.get_arguments()
.filter(|o| !o.is_positional())
.filter(|o| !o.is_hide_set())
.filter(|o| o.is_global_set() == persistent)
.map(|x| x.to_owned())
.collect::<Vec<Arg>>();
arguments.sort_by_key(|o| {
Expand Down
6 changes: 4 additions & 2 deletions tests/snapshots/basic.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
name: basic
description: ''
flags:
-c: ''
-v: ''
persistentflags:
-c: ''
commands:
- name: test
description: Subcommand
flags:
-c: ''
-d*: ''
persistentflags:
-c: ''

0 comments on commit 2d5c60e

Please sign in to comment.