https://github.com/lockbook/cli-rs
Create CLIs with dynamic completions in rust easily
https://github.com/lockbook/cli-rs
Last synced: 5 months ago
JSON representation
Create CLIs with dynamic completions in rust easily
- Host: GitHub
- URL: https://github.com/lockbook/cli-rs
- Owner: lockbook
- Created: 2023-07-19T22:05:09.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2025-10-01T20:21:17.000Z (9 months ago)
- Last Synced: 2025-10-01T22:16:51.834Z (9 months ago)
- Language: Rust
- Homepage:
- Size: 85.9 KB
- Stars: 5
- Watchers: 1
- Forks: 2
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# cli-rs
🚧 wip 🚧
A library to help you quickly write expressive CLIs. Built from the ground up with advanced features like [dynamic completions](https://github.com/clap-rs/clap/issues/1232) in mind.
```rust
Command::name("lockbook")
.subcommand(
Command::name("edit")
.input(Arg::new("target"))
.handler(|target: Arg| println!("editing target file: {}", target.get())),
)
.parse();
```
Specify complicated arguments that are used often:
```rust
let docs = Arg::::new("target-file")
.description("A uuid or path of a lockbook document")
.parser(|str| {...})
.completions(|current_str, cursor_loc| {...});
```
cli-rs will automatically generate contextual help messages, and man pages.
cli-rs will also generate a tiny completions file for every shell which will call your CLI, moving as much of the completion logic into Rust as possible.
# spec
```
command_path --flags positional_args --flags positional_args
```
things for now
+ args are all required and must be provided in order
+ flags are always optional (must impl default) and can be provided out of order
+ flags that aren't booleans follow the form `--key=value`
+ boolean that are boolean are parsed as either `--key`, `--key=false`, or `-k`
+ a command can have subcommands or args & flags, but not both
things for later:
+ support `--key value`
+ can define an environment variable for flag values (cli specified value, env var fallback, then Default::default())
+ subcommands inherit any flags as their own flags
+ additionally all boolean flags can be grouped, such as `-rf`
+ list args (support for optional args)
+ detect invalid configuration at runtime