From 9d22f79ce06f8ebedead0e0528f95ec7e10f1d46 Mon Sep 17 00:00:00 2001 From: coffee-compiler <22056268-coffee-compiler@users.noreply.gitlab.com> Date: Fri, 16 Aug 2024 15:32:50 +0000 Subject: [PATCH] Update cmd_doc_gen to print client command table as well --- common/Cargo.toml | 5 ---- common/src/bin/cmd_doc_gen.rs | 31 ---------------------- voxygen/Cargo.toml | 5 ++++ voxygen/src/bin/cmd_doc_gen.rs | 47 ++++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 36 deletions(-) delete mode 100644 common/src/bin/cmd_doc_gen.rs create mode 100644 voxygen/src/bin/cmd_doc_gen.rs diff --git a/common/Cargo.toml b/common/Cargo.toml index 9e649bf9ca..da75caef94 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -11,7 +11,6 @@ simd = ["vek/platform_intrinsics"] bin_csv = ["ron", "csv", "clap"] bin_graphviz = ["petgraph", "clap"] bin_recipe_gen = ["ron"] -bin_cmd_doc_gen = [] bin_asset_migrate = ["ron"] rrt_pathfinding = ["kiddo"] calendar_events = [] @@ -118,7 +117,3 @@ required-features = ["bin_graphviz"] [[bin]] name = "skill_graphviz" required-features = ["bin_graphviz"] - -[[bin]] -name = "cmd_doc_gen" -required-features = ["bin_cmd_doc_gen"] diff --git a/common/src/bin/cmd_doc_gen.rs b/common/src/bin/cmd_doc_gen.rs deleted file mode 100644 index d85c43a875..0000000000 --- a/common/src/bin/cmd_doc_gen.rs +++ /dev/null @@ -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::>() - .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() - } - ); - } -} diff --git a/voxygen/Cargo.toml b/voxygen/Cargo.toml index a8653d6371..934db0e54a 100644 --- a/voxygen/Cargo.toml +++ b/voxygen/Cargo.toml @@ -35,6 +35,7 @@ egui-ui = ["voxygen-egui", "egui", "egui_wgpu_backend", "egui_winit_platform"] shaderc-from-source = ["shaderc/build-from-source"] discord = ["discord-sdk"] 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. default-publish = [ @@ -174,3 +175,7 @@ name = "meshing_benchmark" [[bin]] name = "img_export" required-features = ["bin_img_export"] + +[[bin]] +name = "cmd_doc_gen" +required-features = ["bin_cmd_doc_gen"] \ No newline at end of file diff --git a/voxygen/src/bin/cmd_doc_gen.rs b/voxygen/src/bin/cmd_doc_gen.rs new file mode 100644 index 0000000000..1d7f8e0e60 --- /dev/null +++ b/voxygen/src/bin/cmd_doc_gen.rs @@ -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::>() + .join(" "); + + format!( + "|/{}|{}|{}|{}|", + keyword, + data.description, + data.needs_role + .map_or("".to_string(), |role| format!("{:?}", role)), + if !args.is_empty() { + format!("`{args}`") + } else { + "".to_owned() + } + ) +}