1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use clap::Parser;
/// GPT-generated CLI using the `clap` crate.
//# Purpose: Demonstrate `clap` CLI using the derive option.
//# Categories: CLI, crates, technique
//# Sample arguments: `-- -bgtv dummy_script.rs`
// Script Runner
#[derive(Debug, Parser)]
#[clap(version = "1.0", author = "Your Name")]
struct Opt {
/// Sets the script to run
script: String,
/// Sets the arguments for the script
#[clap(last = true)]
args: Vec<String>,
/// Sets the level of verbosity
#[clap(short, long)]
verbose: bool,
/// Displays timings
#[clap(short, long)]
timings: bool,
/// Generates something
#[clap(short, long)]
generate: bool,
/// Builds something
#[clap(short, long)]
build: bool,
}
fn main() {
let opt = Opt::parse();
if opt.verbose {
println!("Verbosity enabled");
}
if opt.timings {
println!("Timings enabled");
}
if opt.generate {
println!("Generating something");
}
if opt.build {
println!("Building something");
}
println!("Running script: {}", opt.script);
if !opt.args.is_empty() {
println!("With arguments:");
for arg in &opt.args {
println!("{}", arg);
}
}
}