Update cmd_doc_gen to print client command table as well

This commit is contained in:
coffee-compiler 2024-08-16 15:32:50 +00:00 committed by crabman
parent 09825d6769
commit 9d22f79ce0
4 changed files with 52 additions and 36 deletions

View File

@ -11,7 +11,6 @@ simd = ["vek/platform_intrinsics"]
bin_csv = ["ron", "csv", "clap"] bin_csv = ["ron", "csv", "clap"]
bin_graphviz = ["petgraph", "clap"] bin_graphviz = ["petgraph", "clap"]
bin_recipe_gen = ["ron"] bin_recipe_gen = ["ron"]
bin_cmd_doc_gen = []
bin_asset_migrate = ["ron"] bin_asset_migrate = ["ron"]
rrt_pathfinding = ["kiddo"] rrt_pathfinding = ["kiddo"]
calendar_events = [] calendar_events = []
@ -118,7 +117,3 @@ required-features = ["bin_graphviz"]
[[bin]] [[bin]]
name = "skill_graphviz" name = "skill_graphviz"
required-features = ["bin_graphviz"] required-features = ["bin_graphviz"]
[[bin]]
name = "cmd_doc_gen"
required-features = ["bin_cmd_doc_gen"]

View File

@ -1,31 +0,0 @@
use veloren_common::cmd::ServerChatCommand;
/// 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 ServerChatCommand::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()
}
);
}
}

View File

@ -35,6 +35,7 @@ egui-ui = ["voxygen-egui", "egui", "egui_wgpu_backend", "egui_winit_platform"]
shaderc-from-source = ["shaderc/build-from-source"] shaderc-from-source = ["shaderc/build-from-source"]
discord = ["discord-sdk"] discord = ["discord-sdk"]
bin_img_export = ["common-assets"] bin_img_export = ["common-assets"]
bin_cmd_doc_gen = []
# We don't ship egui with published release builds so a separate feature is required that excludes it. # We don't ship egui with published release builds so a separate feature is required that excludes it.
default-publish = [ default-publish = [
@ -174,3 +175,7 @@ name = "meshing_benchmark"
[[bin]] [[bin]]
name = "img_export" name = "img_export"
required-features = ["bin_img_export"] required-features = ["bin_img_export"]
[[bin]]
name = "cmd_doc_gen"
required-features = ["bin_cmd_doc_gen"]

View File

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