Thanks to visit codestin.com
Credit goes to lib.rs

#parser #clap #automatic #entry-point #proc-macro

macro clap_main

A crate to provide a #[clap_main] macro to automatically parse and pass args to your main function

14 releases

0.2.9 Feb 15, 2024
0.2.8 Feb 15, 2024
0.1.3 Dec 27, 2023
0.1.2 Oct 19, 2023

#659 in Procedural macros

Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App

4,614 downloads per month
Used in 4 crates (3 directly)

GPL-3.0-only

5KB

Clap Main

This crate provides an procmacro #[clap_main] to decorate your entry point function and automatically parse a struct that implements clap::Parser from the cli args.

Example Usage

Requires clap with the derive feature enabled


#[derive(clap::Parser)]
struct CliArgs {
  /// A name to be greeted
  name: String
}

#[clap_main::clap_main]
fn main(CliArgs { name }: CliArgs) {
  println!("Hello {name}");  
}

Dependencies

~155–570KB
~13K SLoC