| Crates.io | clap_jobs_arg |
| lib.rs | clap_jobs_arg |
| version | 1.0.2 |
| created_at | 2025-10-22 12:40:09.446553+00 |
| updated_at | 2025-10-27 08:56:06.156202+00 |
| description | Give your clap parser a --jobs argument |
| homepage | |
| repository | https://github.com/giellatekno/clap_jobs_arg |
| max_upload_size | |
| id | 1895607 |
| size | 18,288 |
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() -> ()) {
// ...
}