From f7ce99550595915efb3d3f7774095976cb3b763b Mon Sep 17 00:00:00 2001 From: Weicao-CatilGrass <1992414357@qq.com> Date: Tue, 9 Jun 2026 17:12:50 +0800 Subject: Add COMPLETION_SUBCOMMAND and is_completing method --- mingling_core/src/comp/comp_ctx.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 mingling_core/src/comp/comp_ctx.rs (limited to 'mingling_core/src/comp') 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 Program +where + C: ProgramCollect, +{ + /// 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) + } +} -- cgit