| Crates.io | cli-builder-macros |
| lib.rs | cli-builder-macros |
| version | 0.1.1 |
| created_at | 2025-11-06 20:05:48.908012+00 |
| updated_at | 2025-11-06 20:40:25.261217+00 |
| description | Macro to make cli creation easy. Also generates commands for help, version, and zsh completions. |
| homepage | |
| repository | https://github.com/jackhamilton/cli-builder-macros |
| max_upload_size | |
| id | 1920244 |
| size | 12,998 |
This macro makes it really easy to make simple CLI programs. It handles keeping your help and version functions up to date, and even generates zsh completions for you.
For example, '--run command', where the --run option is given its own argument.
For example, 'tar -zxf', where z x and f are all part of the same argument but have different effects. We treat all single dash arguments as a shortened version of a longer dash argument.
cli_builder! {
[
// Optional (sets what runs if no arguments are given, defaults to the builtin help function):
// default = help,
CLICommand {
short_flag: "t",
long_flag: "test",
command: test_command,
description: "Run a test"
},
// Any number of additional commands
]
}
fn test_command() {
println!("This is a test");
}
Output:
> cargo run -- -h
Help:
-h, --help: prints help message (you are here)
-v, --version: prints tool version
-zsh, --completions: prints zsh completions for sourcing, add to your shell via e.g. "znap fpath _program_name 'program_name --completions'" for znap
-t, --test: Run a test
> cargo run -- -t
This is a test
A main function will be generated for you, and routing to all cli commands handled from it. It expects static functions at the top level of the file - nothing with &self or &mut self. If you need a runtime object, it is suggested you create that either within the function context or as a static with a pointer.