Skip to content

Commit c71a8a4

Browse files
implement argument flags
1 parent 0f4111a commit c71a8a4

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

src/lib.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ To see all the flags the proxied tool accepts run `cargo-{} -- --help`.{}",
178178
Arg::new("quiet")
179179
.long("quiet")
180180
.short('q')
181+
.action(ArgAction::SetTrue)
181182
.help("Don't print build output from `cargo build`"),
182183
Arg::new("package")
183184
.long("package")
@@ -191,6 +192,7 @@ To see all the flags the proxied tool accepts run `cargo-{} -- --help`.{}",
191192
.help("Number of parallel jobs, defaults to # of CPUs"),
192193
Arg::new("lib")
193194
.long("lib")
195+
.action(ArgAction::SetTrue)
194196
.conflicts_with_all(["bin", "example", "test", "bench"])
195197
.help("Build only this package's library"),
196198
Arg::new("bin")
@@ -215,6 +217,7 @@ To see all the flags the proxied tool accepts run `cargo-{} -- --help`.{}",
215217
.help("Build only the specified bench target"),
216218
Arg::new("release")
217219
.long("release")
220+
.action(ArgAction::SetTrue)
218221
.help("Build artifacts in release mode, with optimizations"),
219222
Arg::new("profile")
220223
.long("profile")
@@ -227,9 +230,11 @@ To see all the flags the proxied tool accepts run `cargo-{} -- --help`.{}",
227230
.help("Space-separated list of features to activate"),
228231
Arg::new("all-features")
229232
.long("all-features")
233+
.action(ArgAction::SetTrue)
230234
.help("Activate all available features"),
231235
Arg::new("no-default-features")
232236
.long("no-default-features")
237+
.action(ArgAction::SetTrue)
233238
.help("Do not activate the `default` feature"),
234239
Arg::new("target")
235240
.long("target")
@@ -244,12 +249,15 @@ To see all the flags the proxied tool accepts run `cargo-{} -- --help`.{}",
244249
.help("Coloring: auto, always, never"),
245250
Arg::new("frozen")
246251
.long("frozen")
252+
.action(ArgAction::SetTrue)
247253
.help("Require Cargo.lock and cache are up to date"),
248254
Arg::new("locked")
249255
.long("locked")
256+
.action(ArgAction::SetTrue)
250257
.help("Require Cargo.lock is up to date"),
251258
Arg::new("offline")
252259
.long("offline")
260+
.action(ArgAction::SetTrue)
253261
.help("Run without accessing the network"),
254262
Arg::new("unstable-features")
255263
.short('Z')
@@ -270,10 +278,10 @@ pub fn run(tool: Tool, matches: ArgMatches) -> Result<i32> {
270278
features.map(|s| s.to_owned()).collect(),
271279
));
272280
}
273-
if matches.contains_id("no-default-features") {
281+
if matches.get_flag("no-default-features") {
274282
metadata_command.features(CargoOpt::NoDefaultFeatures);
275283
}
276-
if matches.contains_id("all-features") {
284+
if matches.get_flag("all-features") {
277285
metadata_command.features(CargoOpt::AllFeatures);
278286
}
279287
let metadata = metadata_command.exec()?;
@@ -360,7 +368,7 @@ pub fn run(tool: Tool, matches: ArgMatches) -> Result<i32> {
360368
// User flags
361369
lltool.args(&tool_args);
362370

363-
if matches.contains_id("verbose") {
371+
if matches.get_flag("verbose") {
364372
eprintln!("{lltool:?}");
365373
}
366374

@@ -397,7 +405,7 @@ fn cargo_build(matches: &ArgMatches, metadata: &Metadata) -> Result<Option<Artif
397405
cargo.arg("build");
398406

399407
let (build_type, verbose) = cargo_build_args(matches, &mut cargo);
400-
let quiet = matches.contains_id("quiet");
408+
let quiet = matches.get_flag("quiet");
401409

402410
cargo.arg("--message-format=json");
403411
cargo.stdout(Stdio::piped());
@@ -450,7 +458,7 @@ fn cargo_build(matches: &ArgMatches, metadata: &Metadata) -> Result<Option<Artif
450458
}
451459

452460
fn cargo_build_args<'a>(matches: &'a ArgMatches, cargo: &mut Command) -> (BuildType<'a>, u64) {
453-
if matches.contains_id("quiet") {
461+
if matches.get_flag("quiet") {
454462
cargo.arg("--quiet");
455463
}
456464

@@ -464,7 +472,7 @@ fn cargo_build_args<'a>(matches: &'a ArgMatches, cargo: &mut Command) -> (BuildT
464472
cargo.arg(jobs);
465473
}
466474

467-
let build_type = if matches.contains_id("lib") {
475+
let build_type = if matches.get_flag("lib") {
468476
cargo.args(["--lib"]);
469477
BuildType::Lib
470478
} else if let Some(bin_name) = matches.get_one::<String>("bin") {
@@ -483,7 +491,7 @@ fn cargo_build_args<'a>(matches: &'a ArgMatches, cargo: &mut Command) -> (BuildT
483491
BuildType::Any
484492
};
485493

486-
if matches.contains_id("release") {
494+
if matches.get_flag("release") {
487495
cargo.arg("--release");
488496
}
489497

@@ -497,10 +505,10 @@ fn cargo_build_args<'a>(matches: &'a ArgMatches, cargo: &mut Command) -> (BuildT
497505
cargo.args(["--features", feature]);
498506
}
499507
}
500-
if matches.contains_id("no-default-features") {
508+
if matches.get_flag("no-default-features") {
501509
cargo.arg("--no-default-features");
502510
}
503-
if matches.contains_id("all-features") {
511+
if matches.get_flag("all-features") {
504512
cargo.arg("--all-features");
505513
}
506514

@@ -520,15 +528,15 @@ fn cargo_build_args<'a>(matches: &'a ArgMatches, cargo: &mut Command) -> (BuildT
520528
cargo.arg(color);
521529
}
522530

523-
if matches.contains_id("frozen") {
531+
if matches.get_flag("frozen") {
524532
cargo.arg("--frozen");
525533
}
526534

527-
if matches.contains_id("locked") {
535+
if matches.get_flag("locked") {
528536
cargo.arg("--locked");
529537
}
530538

531-
if matches.contains_id("offline") {
539+
if matches.get_flag("offline") {
532540
cargo.arg("--offline");
533541
}
534542

0 commit comments

Comments
 (0)