aboutsummaryrefslogtreecommitdiff
path: root/mingling_core
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-05-15 22:21:56 +0800
committer魏曹先生 <1992414357@qq.com>2026-05-15 22:21:56 +0800
commit6d61e0c46d33b917438386191e1e11351359abac (patch)
tree93a402007a4ac1a4b561a454ab758480d7213c0d /mingling_core
parenta2eefa6abb7b7b86ab78466bf5abc4877d255d79 (diff)
Inline `strip_all_flags` and simplify `ShellContext` methods
Simplify `strip_all_flags` by using `Vec::retain` instead of reallocating. Update doc examples to use `ShellContext` methods directly instead of the now-removed `ShellContextHelper`. Rename `as_picker` to `to_picker` for consistency with Rust conventions. Mark doc tests as `ignore` and add necessary imports.
Diffstat (limited to 'mingling_core')
-rw-r--r--mingling_core/src/builds/comp.rs17
-rw-r--r--mingling_core/src/comp/shell_ctx.rs24
2 files changed, 19 insertions, 22 deletions
diff --git a/mingling_core/src/builds/comp.rs b/mingling_core/src/builds/comp.rs
index ad70cd2..8b884c8 100644
--- a/mingling_core/src/builds/comp.rs
+++ b/mingling_core/src/builds/comp.rs
@@ -15,7 +15,10 @@ const TMPL_COMP_PWSH: &str = include_str!("../../tmpls/comps/pwsh.ps1");
/// Scripts are written to the `OUT_DIR` (or `target/` if `OUT_DIR` is not set).
///
/// # Example
-/// ```
+/// ```rust,ignore
+/// # use mingling_core::comp::ShellFlag;
+/// # use mingling_core::build::build_comp_scripts;
+///
/// // Generate completion scripts for "myapp"
/// build_comp_scripts("myapp").unwrap();
///
@@ -53,7 +56,9 @@ pub fn build_comp_scripts(name: &str) -> Result<(), std::io::Error> {
/// resulting completion script to the target directory (typically `target/`).
///
/// # Example
-/// ```
+/// ```rust,ignore
+/// # use mingling_core::comp::ShellFlag;
+/// # use mingling_core::build::build_comp_script;
/// build_comp_script(&ShellFlag::Bash, "myapp").unwrap();
/// ```
pub fn build_comp_script(shell_flag: &ShellFlag, bin_name: &str) -> Result<(), std::io::Error> {
@@ -69,7 +74,9 @@ pub fn build_comp_script(shell_flag: &ShellFlag, bin_name: &str) -> Result<(), s
/// and writes the resulting completion script to the specified directory.
///
/// # Example
-/// ```
+/// ```rust,ignore
+/// # use mingling_core::comp::ShellFlag;
+/// # use mingling_core::build::build_comp_script_to;
/// build_comp_script_to(&ShellFlag::Bash, "myapp", "target/completions").unwrap();
/// ```
pub fn build_comp_script_to(
@@ -93,7 +100,9 @@ pub fn build_comp_script_to(
/// and writes the resulting completion script directly to the specified file path.
///
/// # Example
-/// ```
+/// ```rust,ignore
+/// # use mingling_core::comp::ShellFlag;
+/// # use mingling_core::build::build_comp_script_to_file;
/// build_comp_script_to_file(&ShellFlag::Bash, "myapp", "target/completions/myapp_comp.sh").unwrap();
/// ```
pub fn build_comp_script_to_file(
diff --git a/mingling_core/src/comp/shell_ctx.rs b/mingling_core/src/comp/shell_ctx.rs
index dd2aa86..3134cd6 100644
--- a/mingling_core/src/comp/shell_ctx.rs
+++ b/mingling_core/src/comp/shell_ctx.rs
@@ -106,14 +106,10 @@ impl ShellContext {
///
/// ```
/// # use mingling_core::ShellContext;
- /// # use mingling_macros::suggest;
- /// # use mingling::comp_tools::ShellContextHelper;
- ///
/// let ctx = ShellContext::default();
- /// let helper = ShellContextHelper::from(ctx);
///
/// // Check if either "--insert" or "-i" appears exactly once
- /// if helper.filling_argument_first(["--insert", "-i"]) {
+ /// if ctx.filling_argument_first(["--insert", "-i"]) {
/// // Perform action that should only happen once, example:
/// // return suggest! {
/// // "A", "B", "C"
@@ -135,7 +131,7 @@ impl ShellContext {
return true;
}
}
- return false;
+ false
}
/// Checks if the previous word in the command line arguments matches any of the given flags.
@@ -148,14 +144,10 @@ impl ShellContext {
///
/// ```
/// # use mingling_core::ShellContext;
- /// # use mingling_macros::suggest;
- /// # use mingling::comp_tools::ShellContextHelper;
- ///
/// let ctx = ShellContext::default();
- /// let helper = ShellContextHelper::from(ctx);
///
/// // Check if the previous word is either "--file" or "-f"
- /// if helper.filling_argument(["--file", "-f"]) {
+ /// if ctx.filling_argument(["--file", "-f"]) {
/// // The user is likely expecting a file argument next, example:
/// // return suggest! {
/// // "src/main.rs", "Cargo.toml", "README.md"
@@ -168,7 +160,7 @@ impl ShellContext {
return true;
}
}
- return false;
+ false
}
/// Checks if the user is currently typing a flag argument.
@@ -188,14 +180,10 @@ impl ShellContext {
///
/// ```
/// # use mingling_core::ShellContext;
- /// # use mingling_macros::suggest;
- /// # use mingling::comp_tools::ShellContextHelper;
- ///
/// let ctx = ShellContext::default();
- /// let helper = ShellContextHelper::from(ctx);
///
/// // Check if the user is typing a flag
- /// if helper.typing_argument() {
+ /// if ctx.typing_argument() {
/// // The user is likely entering a flag, example:
/// // return suggest! {
/// // "--help", "--version", "--verbose"
@@ -220,7 +208,7 @@ impl ShellContext {
/// when the user has already typed certain flags. The method processes both
/// regular suggestion sets and file completion suggestions differently.
pub fn strip_typed_argument(&self, suggest: Suggest) -> Suggest {
- let typed = Self::get_typed_arguments(&self);
+ let typed = Self::get_typed_arguments(self);
match suggest {
Suggest::Suggest(mut set) => {
set.retain(|item| !typed.contains(item.suggest()));