diff options
| -rw-r--r-- | .cargo/registry.toml | 12 | ||||
| -rw-r--r-- | Cargo.lock | 1 | ||||
| -rw-r--r-- | Cargo.toml | 3 | ||||
| -rw-r--r-- | build.rs | 47 |
4 files changed, 60 insertions, 3 deletions
diff --git a/.cargo/registry.toml b/.cargo/registry.toml index 060ca0a..f581074 100644 --- a/.cargo/registry.toml +++ b/.cargo/registry.toml @@ -2,14 +2,20 @@ ### Commands ### ################ -[cmd.status] -node = "status" -type = "cmds::status::JVStatusCommand" +# The system will automatically register commands under ./src/cmds/. +# This section is mainly for registering commands not in the automatic registration directory. + +# [cmd.name] +# node = "name" +# type = "your_command::JVUnknownCommand" ################# ### Renderers ### ################# +# Only register renderers here that need to be overridden using the `--renderer` flag. +# After registration, you can use the format `command --renderer renderer_name` to override the renderer. + # Default Renderer [renderer.default] name = "default" @@ -1009,6 +1009,7 @@ dependencies = [ "rust-i18n", "serde", "serde_json", + "string_proc", "strip-ansi-escapes", "thiserror", "tokio", @@ -31,6 +31,9 @@ panic = "abort" strip = true [build-dependencies] +# Just Enough VCS String Formatter +string_proc = { path = "../VersionControl/utils/string_proc/" } + chrono = "0.4" toml = "0.9" @@ -2,6 +2,10 @@ use std::env; use std::path::PathBuf; use std::process::Command; +use string_proc::pascal_case; + +const COMMANDS_PATH: &str = "./src/cmds/"; + const COMPILE_INFO_RS_TEMPLATE: &str = "./templates/compile_info.rs.template"; const COMPILE_INFO_RS: &str = "./src/data/compile_info.rs"; @@ -253,6 +257,7 @@ fn generate_cmd_registry_file(repo_root: &PathBuf) -> Result<(), Box<dyn std::er let mut commands = Vec::new(); let mut nodes = Vec::new(); + // First, collect commands from Registry.toml if let Some(table) = config.as_table() { if let Some(cmd_table) = table.get("cmd") { if let Some(cmd_table) = cmd_table.as_table() { @@ -272,6 +277,48 @@ fn generate_cmd_registry_file(repo_root: &PathBuf) -> Result<(), Box<dyn std::er } } + // Then, automatically register commands from COMMANDS_PATH + let commands_dir = repo_root.join(COMMANDS_PATH); + if commands_dir.exists() && commands_dir.is_dir() { + for entry in std::fs::read_dir(&commands_dir)? { + let entry = entry?; + let path = entry.path(); + + if !path.is_file() { + continue; + } + + let extension = match path.extension() { + Some(ext) => ext, + None => continue, + }; + + if extension != "rs" { + continue; + } + + let file_name = match path.file_stem().and_then(|s| s.to_str()) { + Some(name) => name, + None => continue, + }; + + // Skip files that start with underscore + if file_name.starts_with('_') { + continue; + } + + // Convert filename to PascalCase + let pascal_name = pascal_case!(file_name); + + let key = file_name.to_string(); + let node = file_name.replace(".", " "); + let cmd_type = format!("cmds::{}::JV{}Command", file_name, pascal_name); + + nodes.push(node.clone()); + commands.push((key, node, cmd_type)); + } + } + // Extract the node_if template from the template content const PROCESS_MARKER: &str = "// PROCESS"; const TEMPLATE_START: &str = "// -- TEMPLATE START --"; |
