#cargo-toml #clap #applications #disk #disk-usage #version #consistency

autoclap

๐Ÿ‘ Auto-propagate Cargo.toml infos (name, version, author, repo) into app

23 releases

0.3.15 Feb 19, 2023
0.3.11 Dec 30, 2022
0.3.10 Nov 17, 2022
0.2.2 Apr 2, 2022
0.2.1 Jan 28, 2022

#804 in Development tools

Download history 53/week @ 2024-07-22 44/week @ 2024-07-29 55/week @ 2024-08-05 48/week @ 2024-08-12 34/week @ 2024-08-19 37/week @ 2024-08-26 46/week @ 2024-09-02 18/week @ 2024-09-09 70/week @ 2024-09-16 64/week @ 2024-09-23 47/week @ 2024-09-30 55/week @ 2024-10-07 63/week @ 2024-10-14 40/week @ 2024-10-21 28/week @ 2024-10-28 62/week @ 2024-11-04

196 downloads per month
Used in 7 crates

MIT license

5KB
54 lines

autoclap

CD-auto

This lib builds on top of clap and auto-propagates Cargo.toml infos (name, version, author, repo) into the application using it.

Running app --help now automatically includes this information in its output.

Why?

Cargo.toml is the single source of truth containing application attributes such as:

  • name
  • version
  • author(s)
  • description

This information is usually duplicated in the app's main, leading to potential inconsistencies (update in one place but not another).

Moreover, a crate unifying this would provide consistency across all apps using it.

Finally, code for app initialization is minimal.

Usage

use clap::Command;
use autoclap::autoclap;

fn main() {
    let app = autoclap!();

    app.arg(
        Arg::with_name("myarg")
            .long("myarg")
            .short('m')
            .help("My arg description."),
    );
    let args = app.clone().try_get_matches().unwrap_or_else(|e| e.exit());

    if args.get_flag("update") { /* My implementation.*/}
}

Now, running app --help now produces:

app 0.1.0 :: https://github.com/username/app/releases/tag/0.1.0
Crate Author <crateauthor@e.mail>
๐Ÿงต The crate awesome description.

Releases

The packge repository URL is concatenated with the version of a package to form a URL to a specific release.

This URL goes live when a release with the same version as the crate is published.

autoclap offers out-of-the box support for GitHub.

Dependencies

~1MB
~15K SLoC