diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-08-07 12:59:16 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-08-07 16:57:24 +0800 |
| commit | 9daff4936ed04f7bab247a2eb741e03d6a39c209 (patch) | |
| tree | 860b3275091a7e209d456b31f0a1566499676711 /mingling_cli/src/lib.rs | |
| parent | 32ee3596042cc4e723afd30b87298a13feef7c24 (diff) | |
refactor(cli): move global help and completion to library
Move the global help and completion handlers from the CLI binary
into the library crate so they can be reused by other entry points.
Diffstat (limited to 'mingling_cli/src/lib.rs')
| -rw-r--r-- | mingling_cli/src/lib.rs | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/mingling_cli/src/lib.rs b/mingling_cli/src/lib.rs index 8b25612..524b74b 100644 --- a/mingling_cli/src/lib.rs +++ b/mingling_cli/src/lib.rs @@ -1,4 +1,16 @@ -use mingling::macros::gen_program; +use mingling::{ + ShellContext, Suggest, + consts::HELP_FLAG, + macros::{completion, gen_program, help, suggest}, +}; + +use crate::{ + metadata::setup::{ + ARG_ALL_FEATURES, ARG_FEATURES, ARG_MANIFEST_PATH, ARG_MESSAGE_FORMAT, + ARG_NO_DEFAULT_FEATURES, ARG_NO_DEPS, + }, + utils::display::ColorCode, +}; pub mod diagnostic; pub mod errors; @@ -10,4 +22,22 @@ pub mod pkg_mgr; pub mod proj_mgr; pub mod utils; +#[help] +pub fn help_global(_: EntryFallback) -> String { + include_str!("../help/help.txt").parse_color_code() +} + +#[completion(EntryFallback)] +pub fn complete_global(_ctx: &ShellContext) -> Suggest { + suggest! { + HELP_FLAG: "Show help messages", + ARG_FEATURES.clone(): "List of features to enable", + ARG_MANIFEST_PATH.clone(): "Custom path to Cargo.toml", + ARG_MESSAGE_FORMAT.clone(): "Output message format", + ARG_ALL_FEATURES: "Enable all features", + ARG_NO_DEFAULT_FEATURES: "Disable default features", + ARG_NO_DEPS: "Do not include dependencies in metadata", + } +} + gen_program!(); |
