clap_jobs_arg

Crates.ioclap_jobs_arg
lib.rsclap_jobs_arg
version1.0.2
created_at2025-10-22 12:40:09.446553+00
updated_at2025-10-27 08:56:06.156202+00
descriptionGive your clap parser a --jobs argument
homepage
repositoryhttps://github.com/giellatekno/clap_jobs_arg
max_upload_size
id1895607
size18,288
Anders Lorentsen (Phaqui)

documentation

README

JobsArguments

Give your clap parsers a --jobs (-j) argument.

It can be given alone (only -j on the command line), to use the number of available cpus (as determined by num_cpus), or a number from 1..=N (where N is the number of available cpus).

It also accepts the keywords serial (1), single (1), some (25%), half (50%), most (75%), full, all, or auto (100%).

If -j is not present on the command line, it will default to the number of available cpus.

Usage example (derived Parser):

use clap::Parser;
use clap_jobs_arg::JobsArguments;

#[derive(Parser, Debug)]
#[command()]
struct Args {
    #[command(flatten)]
    jobs: JobsArguments,
}

fn main() {
    let args = Args::parse_from(["cli-name", "-j", "6"]);
    let jobs = args.jobs;
    assert_eq!(jobs, 6);
    println!("User wants {jobs} parallel processes.");

    // notice: deref to usize, or .as_usize()
    do_in_parallel(*jobs, || ());
    do_in_parallel(jobs.as_usize(), || ());
}

fn do_in_parallel(n_procs: usize, f: impl Fn() -> ()) {
    // ...
}
Commit count: 0

cargo fmt