Added cargo cmd-doc-gen to auto-generate the table of commands in the new players/commands.md page in the book

This commit is contained in:
Ben Wallis 2021-08-20 20:07:22 +01:00
parent ef21c433dc
commit c00bca7e93
4 changed files with 38 additions and 1 deletions

View File

@ -4,6 +4,7 @@ rustflags = [
]
[alias]
cmd-doc-gen = "run --features=bin_cmd_doc_gen --bin cmd_doc_gen"
csv-export = "run --manifest-path common/Cargo.toml --features=bin_csv --bin csv_export"
csv-import = "run --manifest-path common/Cargo.toml --features=bin_csv --bin csv_import"
test-server = "run --bin veloren-server-cli --no-default-features"

View File

@ -1,6 +1,6 @@
#!/bin/bash
rm -r target/debug/incremental/* || echo "all good" # TMP FIX FOR 2021-03-22-nightly
time cargo clippy --all-targets --locked --features="bin_compression,bin_csv,bin_graphviz,bin_bot,asset_tweak" -- -D warnings &&
time cargo clippy --all-targets --locked --features="bin_cmd_doc_gen,bin_compression,bin_csv,bin_graphviz,bin_bot,asset_tweak" -- -D warnings &&
# Ensure that the veloren-voxygen default-publish feature builds as it excludes some default features
time cargo clippy -p veloren-voxygen --locked --no-default-features --features="default-publish" -- -D warnings &&
time cargo fmt --all -- --check

View File

@ -10,6 +10,7 @@ hot-reloading = ["common-assets/hot-reloading"]
simd = ["vek/platform_intrinsics"]
bin_csv = ["ron", "csv", "structopt"]
bin_graphviz = ["petgraph"]
bin_cmd_doc_gen = []
default = ["simd"]
@ -98,3 +99,7 @@ required-features = ["bin_csv"]
[[bin]]
name = "recipe_graphviz"
required-features = ["bin_graphviz"]
[[bin]]
name = "cmd_doc_gen"
required-features = ["bin_cmd_doc_gen"]

View File

@ -0,0 +1,31 @@
use veloren_common::cmd::ChatCommand;
/// This binary generates the markdown table used for the `players/commands.md`
/// page in the Veloren Book. It can be run with `cargo cmd-doc-gen`.
fn main() {
println!("|Command|Description|Requires|Arguments|");
println!("|-|-|-|-|");
for cmd in ChatCommand::iter() {
let args = cmd
.data()
.args
.iter()
.map(|arg| arg.usage_string())
.collect::<Vec<String>>()
.join(" ");
println!(
"|/{}|{}|{}|{}|",
cmd.keyword(),
cmd.data().description,
cmd.data()
.needs_role
.map_or("".to_string(), |role| format!("{:?}", role)),
if !args.is_empty() {
format!("`{}`", args)
} else {
"".to_owned()
}
);
}
}