diff options
Diffstat (limited to 'mingling_core/src/comp')
| -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) + } +} |
