Crates.io | terse_cli |
lib.rs | terse_cli |
version | 0.1.4 |
source | src |
created_at | 2024-11-25 21:29:30.663326 |
updated_at | 2024-11-29 19:47:01.180186 |
description | A library for building no-boilerplate CLI apps |
homepage | https://github.com/JeffrayZhang/terse-cli |
repository | https://github.com/JeffrayZhang/terse-cli |
max_upload_size | |
id | 1460797 |
size | 4,037 |
A wrapper around clap that lets you build CLI applications with very little boilerplate code.
Modeled after tiangolo's typer python library, you simply define your commands and subcommands as functions and annotate them with the #[command]
attribute.
This is a work in progress. The core functionality is implemented, but if you want any customization on how your CLI is used (e.g. positional arguments, custom help messages, etc.) those things are not yet supported.
Known issues:
Display
Install both clap and terse_cli:
$ cargo add clap --features derive
$ cargo add terse_cli
Below snippet is from ./example/main.rs.
use clap::Parser;
use terse_cli::{command, subcommands};
/// Example: cargo run -- command-one --a 3
#[command]
fn command_one(a: i32, b: Option<i32>) -> i32 {
a + b.unwrap_or(0)
}
/// Example: cargo run -- my-subcommands command-two --name Bob
#[command]
fn command_two(name: String) -> String {
format!("hello {}", name)
}
/// Example: cargo run -- my-subcommands command-three --a 7 --b 3
#[command]
fn command_three(a: i32, b: i32) -> String {
format!("the difference is {}", a - b)
}
/// Example: cargo run -- my-subcommands command-four
#[command]
fn command_four() -> String {
"command four".to_string()
}
subcommands!(
/// These are the subcommands
my_subcommands, [command_two, command_three, command_four]);
subcommands!(
/// Example docs for the "root"
cli, [command_one, my_subcommands]);
fn main() {
cli::run(cli::Args::parse());
}
// you can also use `--help` as you would expect
// Example: cargo run -- my-subcommands --help