From 9daff4936ed04f7bab247a2eb741e03d6a39c209 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Fri, 7 Aug 2026 12:59:16 +0800 Subject: 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. --- mingling_cli/src/bin/cli.rs | 36 ++---------------------------------- mingling_cli/src/lib.rs | 32 +++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 35 deletions(-) (limited to 'mingling_cli') diff --git a/mingling_cli/src/bin/cli.rs b/mingling_cli/src/bin/cli.rs index 28362e0..fe2e60a 100644 --- a/mingling_cli/src/bin/cli.rs +++ b/mingling_cli/src/bin/cli.rs @@ -1,20 +1,6 @@ -use mingling::{ - ShellContext, Suggest, - consts::HELP_FLAG, - macros::{completion, help, suggest}, - setup::{ExitCodeSetup, picker::HelpFlagSetup}, -}; +use mingling::setup::{ExitCodeSetup, picker::HelpFlagSetup}; use mingling_cli::{ - EntryFallback, ThisProgram, - linter::registry::LintRegistrySetup, - metadata::{ - MinglingMetadataSetup, - setup::{ - ARG_ALL_FEATURES, ARG_FEATURES, ARG_MANIFEST_PATH, ARG_MESSAGE_FORMAT, - ARG_NO_DEFAULT_FEATURES, ARG_NO_DEPS, - }, - }, - utils::display::ColorCode, + ThisProgram, linter::registry::LintRegistrySetup, metadata::MinglingMetadataSetup, }; #[tokio::main] @@ -31,21 +17,3 @@ async fn main() { // Exec program.exec_and_exit().await; } - -#[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", - } -} 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!(); -- cgit