aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-06-07 02:56:48 +0800
committer魏曹先生 <1992414357@qq.com>2026-06-07 02:56:48 +0800
commit21defab2fc95f1e1d0639b66ab2c449266a114fe (patch)
tree587cc0ca98cfc461366375abe62b143ec1ec36b2
parent91e847bf873ff2e404554ea7bb97fad7beac0530 (diff)
Rename cargo style functions and remove unused imports
-rw-r--r--mling/src/bin/mling.rs3
-rw-r--r--mling/src/cargo_style.rs24
-rw-r--r--mling/src/lib.rs22
3 files changed, 33 insertions, 16 deletions
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>) -> String {
+pub fn get_cargo_info_format(str: impl Into<String>) -> 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>) -> 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>) -> String {
+pub fn get_cargo_error_format(str: impl Into<String>) -> 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!();