veloren/common/src/bin/cmd_doc_gen.rs

32 lines
899 B
Rust

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()
}
);
}
}