I built a macro that lets you write CLI apps with zero boilerplate

290 points eficiency

https://crates.io/crates/terse\_cli

👋 I'm a python dev who recently joined the rust community, and in the python world we have typer -- you write any typed function and it turns it into a CLI command using a decorator.

Clap's derive syntax still feels like a lot of unnecessary structs/enums to me, so I built a macro that essentially builds the derive syntax for you (based on function params and their types).

use clap::Parser;
use terse_cli::{command, subcommands};

#[command]
fn add(a: i32, b: Option<i32>) -> i32 {
    a + b.unwrap_or(0)
}

#[command]
fn greet(name: String) -> String {
    format!("hello {}!", name)
}

subcommands!(cli, [add, greet]);

fn main() {
    cli::run(cli::Args::parse());
}

That program produces a cli like this:

$ cargo run add --a 3 --b 4
7

$ cargo run greet --name Bob
hello Bob!

$ cargo run help
Usage: stuff <COMMAND>

Commands:
  add    
  greet  
  help   Print this message or the help of the given subcommand(s)

Options:
  -h, --help     Print help
  -V, --version  Print version

Give it a try, tell me what you like/dislike, and it's open for contributions :)