From 32ee3596042cc4e723afd30b87298a13feef7c24 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Fri, 7 Aug 2026 12:52:46 +0800 Subject: chore: move CLI entry to bin and restructure imports Move the CLI binary from `src/main.rs` to `src/bin/cli.rs` and move shared program generation into a new lib.rs module. --- mingling_cli/Cargo.toml | 2 +- mingling_cli/src/bin/cli.rs | 51 +++++++++++++++++++++++++++++++++++++ mingling_cli/src/lib.rs | 13 ++++++++++ mingling_cli/src/main.rs | 61 --------------------------------------------- 4 files changed, 65 insertions(+), 62 deletions(-) create mode 100644 mingling_cli/src/bin/cli.rs create mode 100644 mingling_cli/src/lib.rs delete mode 100644 mingling_cli/src/main.rs diff --git a/mingling_cli/Cargo.toml b/mingling_cli/Cargo.toml index c52eefd..94b0c69 100644 --- a/mingling_cli/Cargo.toml +++ b/mingling_cli/Cargo.toml @@ -17,7 +17,7 @@ path = "src/bin/wrapper.rs" [[bin]] name = "mingling-cli" -path = "src/main.rs" +path = "src/bin/cli.rs" [dependencies.mingling] path = "../mingling" diff --git a/mingling_cli/src/bin/cli.rs b/mingling_cli/src/bin/cli.rs new file mode 100644 index 0000000..28362e0 --- /dev/null +++ b/mingling_cli/src/bin/cli.rs @@ -0,0 +1,51 @@ +use mingling::{ + ShellContext, Suggest, + consts::HELP_FLAG, + macros::{completion, help, suggest}, + 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, +}; + +#[tokio::main] +async fn main() { + let mut program = ThisProgram::new(); + + // Setups + program.with_setup(HelpFlagSetup::default()); + program.with_setup(ExitCodeSetup::default()); + + program.with_setup(MinglingMetadataSetup); + program.with_setup(LintRegistrySetup); + + // 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 new file mode 100644 index 0000000..8b25612 --- /dev/null +++ b/mingling_cli/src/lib.rs @@ -0,0 +1,13 @@ +use mingling::macros::gen_program; + +pub mod diagnostic; +pub mod errors; +pub mod linter; +pub mod lints; +pub mod message; +pub mod metadata; +pub mod pkg_mgr; +pub mod proj_mgr; +pub mod utils; + +gen_program!(); diff --git a/mingling_cli/src/main.rs b/mingling_cli/src/main.rs deleted file mode 100644 index 324118b..0000000 --- a/mingling_cli/src/main.rs +++ /dev/null @@ -1,61 +0,0 @@ -use crate::{ - linter::registry::LintRegistrySetup, - metadata::{ - MinglingMetadataSetup, - setup::{ - ARG_ALL_FEATURES, ARG_FEATURES, ARG_MANIFEST_PATH, ARG_MESSAGE_FORMAT, - ARG_NO_DEFAULT_FEATURES, ARG_NO_DEPS, - }, - }, -}; -use mingling::{ - ShellContext, Suggest, - consts::HELP_FLAG, - macros::{completion, gen_program, help, suggest}, - setup::{ExitCodeSetup, picker::HelpFlagSetup}, -}; - -pub mod diagnostic; -pub mod errors; -pub mod linter; -pub mod lints; -pub mod message; -pub mod metadata; -pub mod pkg_mgr; -pub mod proj_mgr; -pub mod utils; - -#[tokio::main] -async fn main() { - let mut program = ThisProgram::new(); - - // Setups - program.with_setup(HelpFlagSetup::default()); - program.with_setup(ExitCodeSetup::default()); - - program.with_setup(MinglingMetadataSetup); - program.with_setup(LintRegistrySetup); - - // Exec - program.exec_and_exit().await; -} - -#[help] -pub fn help_global(_: EntryFallback) -> String { - include_str!("../help/help.txt").to_string() -} - -#[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