From c0e1a18a8280dab5d78a49c0b60460d62a6a1293 Mon Sep 17 00:00:00 2001 From: rsteube Date: Sat, 25 Mar 2023 14:52:06 +0100 Subject: [PATCH] support persistent flags currently adds them to each subcommand (needs fixing) --- src/carapace_spec.rs | 6 ++++-- tests/snapshots/basic.yaml | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/carapace_spec.rs b/src/carapace_spec.rs index 42832f6..bfde1f2 100644 --- a/src/carapace_spec.rs +++ b/src/carapace_spec.rs @@ -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), @@ -82,13 +83,14 @@ fn command_for(cmd: &clap::Command) -> Command { } } -fn flags_for(cmd: &clap::Command) -> Map { +fn flags_for(cmd: &clap::Command, persistent: bool) -> Map { 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::>(); arguments.sort_by_key(|o| { diff --git a/tests/snapshots/basic.yaml b/tests/snapshots/basic.yaml index d2ce182..de0fee7 100644 --- a/tests/snapshots/basic.yaml +++ b/tests/snapshots/basic.yaml @@ -1,11 +1,13 @@ name: basic description: '' flags: - -c: '' -v: '' +persistentflags: + -c: '' commands: - name: test description: Subcommand flags: - -c: '' -d*: '' + persistentflags: + -c: ''