aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-05-29 16:49:35 +0800
committer魏曹先生 <1992414357@qq.com>2026-05-29 16:49:35 +0800
commit2c5355555126cf0e5e6012fb22457638bce9bf4d (patch)
tree020f0006f99655d81941ea1f2e718747ce0a5d33
parentc8d5b062a8f6ef0141e164e8d0249fa1c1d3bd98 (diff)
Rename CompletionDispatcher to CMDCompletion and hide internal types
-rw-r--r--CHANGELOG.md3
-rw-r--r--examples/example-completion/src/main.rs8
-rw-r--r--examples/example-enum-tag/src/main.rs10
-rw-r--r--mingling/src/example_docs.rs18
-rw-r--r--mingling_macros/src/lib.rs20
-rw-r--r--mling/src/cli.rs4
6 files changed, 40 insertions, 23 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fd8f36a..407bcbf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -124,6 +124,9 @@ fn handle_cmd(args: EntryCmd) -> Next {
gen_program!();
```
+7. **\[macros:comp\]** Renamed `CompletionDispatcher` to `CMDCompletion`
+8. **\[macros:comp\]** Marked `CompletionContext` and `CompletionSuggest` as `#[doc(hidden)]`
+
---
### Release 0.1.8 (2026-05-18)
diff --git a/examples/example-completion/src/main.rs b/examples/example-completion/src/main.rs
index 7ca23b9..a34ccab 100644
--- a/examples/example-completion/src/main.rs
+++ b/examples/example-completion/src/main.rs
@@ -52,13 +52,13 @@ fn main() {
program.with_dispatcher(CMDGreet);
// --------- IMPORTANT ---------
- // The `comp` feature makes `gen_program!()` generate a CompletionDispatcher automatically
+ // The `comp` feature makes `gen_program!()` generate a CMDCompletion automatically
// It adds a hidden `__comp` subcommand for communication with the completion script
- program.with_dispatcher(crate::CompletionDispatcher);
+ program.with_dispatcher(crate::CMDCompletion);
// --------- IMPORTANT ---------
// TIP: Note that the completion script reads stdout,
- // so make sure no output is produced before the CompletionDispatcher is dispatched.
+ // so make sure no output is produced before the CMDCompletion is dispatched.
program.exec_and_exit();
}
@@ -109,7 +109,7 @@ pack!(ResultName = (u8, String));
#[chain]
fn handle_greet(args: EntryGreet) -> Next {
let result: ResultName = args
- .pick(["-r", "--repeat"])
+ .pick_or(["-r", "--repeat"], 1)
.pick_or((), "World")
.unpack()
.into();
diff --git a/examples/example-enum-tag/src/main.rs b/examples/example-enum-tag/src/main.rs
index 05419f7..30439f5 100644
--- a/examples/example-enum-tag/src/main.rs
+++ b/examples/example-enum-tag/src/main.rs
@@ -16,8 +16,8 @@
//! ```
use mingling::{
- EnumTag, Groupped, ShellContext, Suggest, macros::suggest_enum, parser::PickableEnum,
- prelude::*,
+ macros::suggest_enum, parser::PickableEnum, prelude::*, EnumTag, Groupped, ShellContext,
+ Suggest,
};
// Define the enum and derive the EnumTag trait
@@ -56,7 +56,9 @@ pub enum ProgrammingLanguages {
#[enum_desc("A general-purpose programming language with clean syntax, known for readability")]
Python,
- #[enum_desc("An object-oriented scripting language, famous for its concise and elegant syntax")]
+ #[enum_desc(
+ "An object-oriented scripting language, famous for its concise and elegant syntax"
+ )]
Ruby,
#[default]
@@ -96,7 +98,7 @@ gen_program!();
fn main() {
let mut program = ThisProgram::new();
- program.with_dispatcher(CompletionDispatcher);
+ program.with_dispatcher(CMDCompletion);
program.with_dispatcher(CMDLanguageSelection);
program.exec_and_exit();
}
diff --git a/mingling/src/example_docs.rs b/mingling/src/example_docs.rs
index a7e8d2e..5b889ba 100644
--- a/mingling/src/example_docs.rs
+++ b/mingling/src/example_docs.rs
@@ -511,13 +511,13 @@ pub mod example_clap_binding {}
/// program.with_dispatcher(CMDGreet);
///
/// // --------- IMPORTANT ---------
-/// // The `comp` feature makes `gen_program!()` generate a CompletionDispatcher automatically
+/// // The `comp` feature makes `gen_program!()` generate a CMDCompletion automatically
/// // It adds a hidden `__comp` subcommand for communication with the completion script
-/// program.with_dispatcher(crate::CompletionDispatcher);
+/// program.with_dispatcher(crate::CMDCompletion);
/// // --------- IMPORTANT ---------
///
/// // TIP: Note that the completion script reads stdout,
-/// // so make sure no output is produced before the CompletionDispatcher is dispatched.
+/// // so make sure no output is produced before the CMDCompletion is dispatched.
/// program.exec_and_exit();
/// }
///
@@ -568,7 +568,7 @@ pub mod example_clap_binding {}
/// #[chain]
/// fn handle_greet(args: EntryGreet) -> Next {
/// let result: ResultName = args
-/// .pick(["-r", "--repeat"])
+/// .pick_or(["-r", "--repeat"], 1)
/// .pick_or((), "World")
/// .unpack()
/// .into();
@@ -843,8 +843,8 @@ pub mod example_dispatch_tree {}
/// Source code (./src/main.rs)
/// ```ignore
/// use mingling::{
-/// EnumTag, Groupped, ShellContext, Suggest, macros::suggest_enum, parser::PickableEnum,
-/// prelude::*,
+/// macros::suggest_enum, parser::PickableEnum, prelude::*, EnumTag, Groupped, ShellContext,
+/// Suggest,
/// };
///
/// // Define the enum and derive the EnumTag trait
@@ -883,7 +883,9 @@ pub mod example_dispatch_tree {}
/// #[enum_desc("A general-purpose programming language with clean syntax, known for readability")]
/// Python,
///
-/// #[enum_desc("An object-oriented scripting language, famous for its concise and elegant syntax")]
+/// #[enum_desc(
+/// "An object-oriented scripting language, famous for its concise and elegant syntax"
+/// )]
/// Ruby,
///
/// #[default]
@@ -923,7 +925,7 @@ pub mod example_dispatch_tree {}
///
/// fn main() {
/// let mut program = ThisProgram::new();
-/// program.with_dispatcher(CompletionDispatcher);
+/// program.with_dispatcher(CMDCompletion);
/// program.with_dispatcher(CMDLanguageSelection);
/// program.exec_and_exit();
/// }
diff --git a/mingling_macros/src/lib.rs b/mingling_macros/src/lib.rs
index dd1afd4..b09eedf 100644
--- a/mingling_macros/src/lib.rs
+++ b/mingling_macros/src/lib.rs
@@ -1116,6 +1116,7 @@ pub fn program_comp_gen(input: TokenStream) -> TokenStream {
#[cfg(feature = "async")]
let fn_exec_comp = quote! {
+ #[doc(hidden)]
#[::mingling::macros::chain(#name)]
pub async fn __exec_completion(prev: CompletionContext) -> Next {
let read_ctx = ::mingling::ShellContext::try_from(prev.inner);
@@ -1131,6 +1132,7 @@ pub fn program_comp_gen(input: TokenStream) -> TokenStream {
#[cfg(not(feature = "async"))]
let fn_exec_comp = quote! {
+ #[doc(hidden)]
#[::mingling::macros::chain(#name)]
pub fn __exec_completion(prev: CompletionContext) -> Next {
let read_ctx = ::mingling::ShellContext::try_from(prev.inner);
@@ -1145,17 +1147,25 @@ pub fn program_comp_gen(input: TokenStream) -> TokenStream {
};
let comp_dispatcher = quote! {
- ::mingling::macros::dispatcher!(#name, "__comp", CompletionDispatcher => CompletionContext);
- ::mingling::macros::pack!(
- #name,
- CompletionSuggest = (::mingling::ShellContext, ::mingling::Suggest)
- );
+ #[doc(hidden)]
+ mod __internal_completion_mod {
+ use super::#name;
+ ::mingling::macros::dispatcher!(#name, "__comp", CMDCompletion => CompletionContext);
+ ::mingling::macros::pack!(
+ #name,
+ CompletionSuggest = (::mingling::ShellContext, ::mingling::Suggest)
+ );
+ }
+ use __internal_completion_mod::CompletionContext;
+ use __internal_completion_mod::CompletionSuggest;
+ pub use __internal_completion_mod::CMDCompletion;
#fn_exec_comp
::mingling::macros::register_type!(CompletionContext);
#[allow(unused)]
+ #[doc(hidden)]
#[::mingling::macros::renderer(#name)]
pub fn __render_completion(prev: CompletionSuggest) {
let (ctx, suggest) = prev.inner;
diff --git a/mling/src/cli.rs b/mling/src/cli.rs
index 055f69c..87ba4f0 100644
--- a/mling/src/cli.rs
+++ b/mling/src/cli.rs
@@ -3,7 +3,7 @@ use mingling::{
setup::{BasicProgramSetup, GeneralRendererSetup},
};
-use crate::{CompletionDispatcher, DispatcherNotFound, ThisProgram, display::markdown};
+use crate::{CMDCompletion, DispatcherNotFound, ThisProgram, display::markdown};
pub mod list;
pub use list::*;
@@ -23,7 +23,7 @@ pub fn cli_entry() {
// Plugins
program.with_setup(BasicProgramSetup);
program.with_setup(GeneralRendererSetup);
- program.with_dispatcher(CompletionDispatcher);
+ program.with_dispatcher(CMDCompletion);
if program.pick_global_flag(["-v", "--version"]) {
println!("{}", include_str!("../res/version.txt").trim_end());