aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-04-14 16:10:45 +0800
committer魏曹先生 <1992414357@qq.com>2026-04-14 16:10:45 +0800
commit7231e55bc3eed0e4d992fda417b71adadd66c1f8 (patch)
tree81262314dfecce1c808dd2d2ac302841717e54d0
parent6e034378e1e8b5e86e498a68f647ee9973462d6d (diff)
Update README and add docs README generation
-rw-r--r--README.md5
-rw-r--r--dev_tools/src/bin/refresh-examples.rs96
2 files changed, 60 insertions, 41 deletions
diff --git a/README.md b/README.md
index 22604ee..09f19cb 100644
--- a/README.md
+++ b/README.md
@@ -38,7 +38,10 @@
## Intro
-`Mingling` is a Rust command-line framework. Its name comes from the Chinese Pinyin for "命令", which means "Command".
+[`Mingling`](https://github.com/CatilGrass/mingling) is a **proc-macro and type system-based** Rust CLI framework, suitable for developing complex command-line programs with numerous subcommands.
+
+> BTW: Its name comes from the Chinese Pinyin "mìng lìng", meaning "Command". 😄
+
## Quick Start
diff --git a/dev_tools/src/bin/refresh-examples.rs b/dev_tools/src/bin/refresh-examples.rs
index be5da82..08ecf90 100644
--- a/dev_tools/src/bin/refresh-examples.rs
+++ b/dev_tools/src/bin/refresh-examples.rs
@@ -6,8 +6,64 @@ use just_template::{Template, tmpl};
const EXAMPLE_ROOT: &str = "./examples/";
const OUTPUT_PATH: &str = "./mingling/src/example_docs.rs";
+const DOCS_README_FILE: &str = "./docs/README.md";
+
+const README_CONTENT: &str = include_str!("../../../README.md");
const TEMPLATE_CONTENT: &str = include_str!("../../../mingling/src/example_docs.rs.tmpl");
+fn main() {
+ gen_example_doc_module();
+ gen_docs_readme();
+}
+
+fn gen_example_doc_module() {
+ let mut template = Template::from(TEMPLATE_CONTENT);
+ let repo_root = find_git_repo().unwrap();
+ let example_root = repo_root.join(EXAMPLE_ROOT);
+ let mut examples = Vec::new();
+ if let Ok(entries) = std::fs::read_dir(&example_root) {
+ for entry in entries.flatten() {
+ if let Ok(file_type) = entry.file_type() {
+ if file_type.is_dir() {
+ let example_name = entry.file_name().to_string_lossy().to_string();
+ let example_content = ExampleContent::read(&example_name);
+ examples.push(example_content);
+ }
+ }
+ }
+ }
+
+ for example in examples {
+ tmpl!(template += {
+ examples {
+ (
+ example_header = example.header,
+ example_import = example.cargo_toml,
+ example_code = example.code,
+ example_name = snake_case!(example.name)
+ )
+ }
+ });
+ }
+
+ let template_str = template.to_string();
+ let template_str = template_str
+ .lines()
+ .map(|line| line.trim_end())
+ .collect::<Vec<_>>()
+ .join("\n")
+ + "\n";
+ std::fs::write(repo_root.join(OUTPUT_PATH), template_str).unwrap();
+}
+
+fn gen_docs_readme() {
+ let repo_root = find_git_repo().unwrap();
+
+ // Convert relative addresses in the documentation
+ let content = README_CONTENT.replace("docs/res/", "res/");
+ std::fs::write(repo_root.join(DOCS_README_FILE), content).unwrap();
+}
+
struct ExampleContent {
name: String,
header: String,
@@ -88,46 +144,6 @@ impl ExampleContent {
}
}
-fn main() {
- let mut template = Template::from(TEMPLATE_CONTENT);
- let repo_root = find_git_repo().unwrap();
- let example_root = repo_root.join(EXAMPLE_ROOT);
- let mut examples = Vec::new();
- if let Ok(entries) = std::fs::read_dir(&example_root) {
- for entry in entries.flatten() {
- if let Ok(file_type) = entry.file_type() {
- if file_type.is_dir() {
- let example_name = entry.file_name().to_string_lossy().to_string();
- let example_content = ExampleContent::read(&example_name);
- examples.push(example_content);
- }
- }
- }
- }
-
- for example in examples {
- tmpl!(template += {
- examples {
- (
- example_header = example.header,
- example_import = example.cargo_toml,
- example_code = example.code,
- example_name = snake_case!(example.name)
- )
- }
- });
- }
-
- let template_str = template.to_string();
- let template_str = template_str
- .lines()
- .map(|line| line.trim_end())
- .collect::<Vec<_>>()
- .join("\n")
- + "\n";
- std::fs::write(repo_root.join(OUTPUT_PATH), template_str).unwrap();
-}
-
fn find_git_repo() -> Option<std::path::PathBuf> {
let mut current_dir = std::env::current_dir().ok()?;