From 21defab2fc95f1e1d0639b66ab2c449266a114fe Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sun, 7 Jun 2026 02:56:48 +0800 Subject: Rename cargo style functions and remove unused imports --- mling/src/bin/mling.rs | 3 +-- mling/src/cargo_style.rs | 24 ++++++++++++------------ mling/src/lib.rs | 22 ++++++++++++++++++++-- 3 files changed, 33 insertions(+), 16 deletions(-) (limited to 'mling') diff --git a/mling/src/bin/mling.rs b/mling/src/bin/mling.rs index 587aeb9..d48f439 100644 --- a/mling/src/bin/mling.rs +++ b/mling/src/bin/mling.rs @@ -1,6 +1,5 @@ use std::{env::current_dir, process::exit}; -use colored::Colorize; use mingling::{ Program, hook::ProgramHook, @@ -65,7 +64,7 @@ fn main() { if result.exit_code == 0 && render_output { println!("{}", result.trim()); } else if error_output { - eprintln!("{}", result.trim().bright_red()); + eprintln!("{}", result.trim()); } } exit(result.exit_code); diff --git a/mling/src/cargo_style.rs b/mling/src/cargo_style.rs index 7663985..048e75f 100644 --- a/mling/src/cargo_style.rs +++ b/mling/src/cargo_style.rs @@ -24,10 +24,10 @@ use colored::Colorize; #[macro_export] macro_rules! format_cargo { ($fmt:literal, $($arg:tt)*) => { - $crate::format_cargo(format!($fmt, $($arg)*)) + $crate::get_cargo_info_format(format!($fmt, $($arg)*)) }; ($cmd:expr) => { - $crate::format_cargo($cmd) + $crate::get_cargo_info_format($cmd) }; } @@ -47,10 +47,10 @@ macro_rules! format_cargo { #[macro_export] macro_rules! eformat_cargo { ($fmt:literal, $($arg:tt)*) => { - $crate::eformat_cargo(format!($fmt, $($arg)*)) + $crate::get_cargo_error_format(format!($fmt, $($arg)*)) }; ($cmd:expr) => { - $crate::eformat_cargo($cmd) + $crate::get_cargo_error_format($cmd) }; } @@ -69,10 +69,10 @@ macro_rules! eformat_cargo { #[macro_export] macro_rules! println_cargo { ($fmt:literal, $($arg:tt)*) => { - println!("{}", $crate::format_cargo(format!($fmt, $($arg)*))) + println!("{}", $crate::get_cargo_info_format(format!($fmt, $($arg)*))) }; ($cmd:expr) => { - println!("{}", $crate::format_cargo($cmd)) + println!("{}", $crate::get_cargo_info_format($cmd)) }; } @@ -91,10 +91,10 @@ macro_rules! println_cargo { #[macro_export] macro_rules! eprintln_cargo { ($fmt:literal, $($arg:tt)*) => { - eprintln!("{}", $crate::eformat_cargo(format!($fmt, $($arg)*))) + eprintln!("{}", $crate::get_cargo_error_format(format!($fmt, $($arg)*))) }; ($cmd:expr) => { - eprintln!("{}", $crate::eformat_cargo($cmd)) + eprintln!("{}", $crate::get_cargo_error_format($cmd)) }; } @@ -114,10 +114,10 @@ macro_rules! eprintln_cargo { /// # Examples /// /// ```ignore -/// format_cargo("Compiling: my_program.rs"); +/// get_cargo_info_format("Compiling: my_program.rs"); /// // returns " Compiling my_program.rs" /// ``` -pub fn format_cargo(str: impl Into) -> String { +pub fn get_cargo_info_format(str: impl Into) -> String { let s = str.into(); let (prefix, content) = if let Some(pos) = s.find(':') { ( @@ -153,9 +153,9 @@ pub fn format_cargo(str: impl Into) -> String { /// # Examples /// /// ```ignore -/// eformat_cargo("something went wrong"); +/// get_cargo_error_format("something went wrong"); /// // returns "error: something went wrong" /// ``` -pub fn eformat_cargo(str: impl Into) -> String { +pub fn get_cargo_error_format(str: impl Into) -> String { format!("{}: {}", "error".bold().bright_red(), str.into()) } diff --git a/mling/src/lib.rs b/mling/src/lib.rs index 2ea6305..0f58ccc 100644 --- a/mling/src/lib.rs +++ b/mling/src/lib.rs @@ -1,12 +1,30 @@ #![allow(unused_imports)] -use mingling::macros::gen_program; +use mingling::{ + macros::{gen_program, r_println, renderer}, + res::ResExitCode, +}; -pub mod cargo_style; +mod cargo_style; +pub use cargo_style::*; pub mod display; pub mod res; mod proj_mgr; use proj_mgr::*; +use crate::display::markdown; + +#[renderer] +pub fn render_error_dispatch_not_found(err: ErrorDispatcherNotFound, ec: &mut ResExitCode) { + if err.len() < 1 { + r_println!("{}", markdown(include_str!("helps/mling_help.txt"))); + ec.exit_code = 0; + } else { + let s = eformat_cargo!("Cannot find subcommand \"{}\"", err.join(" ")); + r_println!("{}", s); + ec.exit_code = 1; + } +} + gen_program!(); -- cgit