aboutsummaryrefslogtreecommitdiff
path: root/dev_tools/src/lib.rs
diff options
context:
space:
mode:
authorWeicao-CatilGrass <1992414357@qq.com>2026-05-31 02:42:52 +0800
committer魏曹先生 <1992414357@qq.com>2026-05-31 17:19:20 +0800
commit2aa7bda3cb21ce6c052b82e08bcab79a625d04f2 (patch)
treef10b89007fc67ca1a948f34abe6869b49296b932 /dev_tools/src/lib.rs
parent3aa409a55e4f2f0ab41b0949cc06eb13c2da4a43 (diff)
Enhance code quality across the entire codebase
Diffstat (limited to 'dev_tools/src/lib.rs')
-rw-r--r--dev_tools/src/lib.rs30
1 files changed, 22 insertions, 8 deletions
diff --git a/dev_tools/src/lib.rs b/dev_tools/src/lib.rs
index 1e62a2d..59eed0a 100644
--- a/dev_tools/src/lib.rs
+++ b/dev_tools/src/lib.rs
@@ -30,6 +30,11 @@ macro_rules! eprintln_cargo_style {
};
}
+/// Print a message in cargo style format, with bold green prefix.
+///
+/// # Panics
+///
+/// Panics if the prefix (text before the first `:`) exceeds 12 characters.
pub fn println_cargo_style(str: impl Into<String>) {
let s = str.into();
let (prefix, content) = if let Some(pos) = s.find(':') {
@@ -38,16 +43,15 @@ pub fn println_cargo_style(str: impl Into<String>) {
s[pos + 1..].trim_start().to_string(),
)
} else {
- ("".to_string(), s.trim().to_string())
+ (String::new(), s.trim().to_string())
};
- if prefix.len() > 12 {
- panic!(
- "prefix length exceeds 12: '{}' has length {}",
- prefix,
- prefix.len()
- );
- }
+ assert!(
+ prefix.len() <= 12,
+ "prefix length exceeds 12: '{}' has length {}",
+ prefix,
+ prefix.len()
+ );
let padding = " ".repeat(12 - prefix.len());
@@ -63,6 +67,15 @@ pub fn eprintln_cargo_style(str: impl Into<String>) {
println!("{}: {}", "error".bold().bright_red(), str.into());
}
+/// Run a shell command and return its exit status.
+///
+/// # Panics
+///
+/// Panics if the shell command cannot be spawned (e.g. the shell binary is not found).
+///
+/// # Errors
+///
+/// Returns `Err` with the exit code if the command finishes with a non-zero exit code.
pub fn run_cmd(cmd: impl Into<String>) -> Result<(), i32> {
let shell = if cfg!(target_os = "windows") {
"powershell"
@@ -84,6 +97,7 @@ pub fn run_cmd(cmd: impl Into<String>) -> Result<(), i32> {
}
}
+#[must_use]
pub fn cargo_tomls() -> Vec<std::path::PathBuf> {
let mut cargo_tomls = Vec::new();
let mut dirs = vec![std::path::PathBuf::from(".")];