diff options
| author | Weicao-CatilGrass <1992414357@qq.com> | 2026-06-09 17:12:50 +0800 |
|---|---|---|
| committer | Weicao-CatilGrass <1992414357@qq.com> | 2026-06-09 17:14:08 +0800 |
| commit | f7ce99550595915efb3d3f7774095976cb3b763b (patch) | |
| tree | 378bdacea64bb22d41844eb9298c6b67b260f8b5 /mingling_core/src/comp/comp_ctx.rs | |
| parent | bcdd642b269a3342a07d625139c647b0501fa7c7 (diff) | |
Add COMPLETION_SUBCOMMAND and is_completing method
Diffstat (limited to 'mingling_core/src/comp/comp_ctx.rs')
| -rw-r--r-- | mingling_core/src/comp/comp_ctx.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/mingling_core/src/comp/comp_ctx.rs b/mingling_core/src/comp/comp_ctx.rs new file mode 100644 index 0000000..02e79c5 --- /dev/null +++ b/mingling_core/src/comp/comp_ctx.rs @@ -0,0 +1,19 @@ +use crate::{COMPLETION_SUBCOMMAND, Program, ProgramCollect}; + +impl<C> Program<C> +where + C: ProgramCollect<Enum = C>, +{ + /// Checks whether the program is currently in a completion mode. + /// + /// This is determined by checking if the special completion subcommand + /// (defined by [`COMPLETION_SUBCOMMAND`]) appears among the parsed arguments. + /// When `true`, the program should generate shell completions instead of + /// running its normal execution path. + pub fn is_completing(&self) -> bool { + // Check if the first argument (args[1]) is the completion subcommand + self.args + .get(1) + .is_some_and(|arg| arg == COMPLETION_SUBCOMMAND) + } +} |
