Skip to content

Commit 37c2fb4

Browse files
authored
feat(cli): add support for global CLI arguments (#2772)
1 parent 27c2193 commit 37c2fb4

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

.changes/add-global-flag-cli.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"cli": minor
3+
"cli-js": minor
4+
---
5+
6+
Added a new `global` boolean flag to the `CliArg` struct to support global CLI arguments. This flag allows arguments like `--verbose` to be marked as global and automatically propagated to all subcommands, enabling consistent availability throughout the CLI.
7+
8+
The new field is optional and defaults to false.

plugins/cli/src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ pub struct Arg {
114114
/// It does not define position in the argument list as a whole. When utilized with multiple=true,
115115
/// only the last positional argument may be defined as multiple (i.e. the one with the highest index).
116116
pub index: Option<usize>,
117+
/// Specifies whether the argument should be global.
118+
///
119+
/// Global arguments are propagated to all subcommands automatically,
120+
/// making them available throughout the CLI regardless of where they are defined.
121+
#[serde(default)]
122+
pub global: bool,
117123
}
118124

119125
/// describes a CLI configuration

plugins/cli/src/parser.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,5 +278,7 @@ fn get_arg(arg_name: String, arg: &Arg) -> ClapArg {
278278
clap_arg = bind_value_arg!(arg, clap_arg, require_equals);
279279
clap_arg = bind_value_arg!(arg, clap_arg, index);
280280

281+
clap_arg = clap_arg.global(arg.global);
282+
281283
clap_arg
282284
}

0 commit comments

Comments
 (0)