autoclap

Crates.ioautoclap
lib.rsautoclap
version0.3.15
sourcesrc
created_at2022-01-27 20:32:31.143453
updated_at2023-02-19 08:50:55.700689
description๐Ÿ‘ Auto-propagate Cargo.toml infos (name, version, author, repo) into app.
homepage
repositoryhttps://github.com/mihaigalos/autoclap
max_upload_size
id522742
size6,373
Mihai Galos (mihaigalos)

documentation

README

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.

Commit count: 118

cargo fmt