@@ -54,6 +54,9 @@ const HELP: &[(&str, &str, &str, &[&str])] = &[
54
54
"Skip passing --features flag to `cargo` if that feature does not exist in the package" ,
55
55
& [ ] ,
56
56
) ,
57
+ ( "" , "--clean-per-run" , "Remove artifacts for that package before running the command" , & [
58
+ "If used this flag with --workspace, --each-feature, or --feature-powerset, artifacts will be removed before each run."
59
+ ] ) ,
57
60
( "-v" , "--verbose" , "Use verbose output" , & [ "This flag will be propagated to cargo." ] ) ,
58
61
( "" , "--color <WHEN>" , "Coloring: auto, always, never" , & [
59
62
"This flag will be propagated to cargo." ,
@@ -184,6 +187,8 @@ pub(crate) struct Args {
184
187
pub ( crate ) optional_deps : bool ,
185
188
/// --skip-no-default-features
186
189
pub ( crate ) skip_no_default_features : bool ,
190
+ /// --clean-per-run
191
+ pub ( crate ) clean_per_run : bool ,
187
192
188
193
// flags that will be propagated to cargo
189
194
/// --features <FEATURES>...
@@ -264,6 +269,7 @@ pub(crate) fn args(coloring: &mut Option<Coloring>) -> Result<Option<Args>> {
264
269
let mut ignore_non_exist_features = false ;
265
270
let mut optional_deps = false ;
266
271
let mut skip_no_default_features = false ;
272
+ let mut clean_per_run = false ;
267
273
268
274
let res = ( || -> Result < ( ) > {
269
275
while let Some ( arg) = args. next ( ) {
@@ -284,31 +290,31 @@ pub(crate) fn args(coloring: &mut Option<Coloring>) -> Result<Option<Args>> {
284
290
continue ;
285
291
}
286
292
287
- macro_rules! parse_arg1 {
288
- ( $ident : ident, $propagate: expr, $pat: expr, $help: expr) => {
293
+ macro_rules! parse_opt {
294
+ ( $opt : ident, $propagate: expr, $pat: expr, $help: expr) => {
289
295
if arg == $pat {
290
- if $ident . is_some( ) {
296
+ if $opt . is_some( ) {
291
297
return Err ( multi_arg( $help, subcommand. as_ref( ) ) ) ;
292
298
}
293
299
let next =
294
300
args. next( ) . ok_or_else( || req_arg( $help, subcommand. as_ref( ) ) ) ?;
295
301
if $propagate {
296
- $ident = Some ( next. clone( ) ) ;
302
+ $opt = Some ( next. clone( ) ) ;
297
303
leading. push( arg) ;
298
304
leading. push( next) ;
299
305
} else {
300
- $ident = Some ( next) ;
306
+ $opt = Some ( next) ;
301
307
}
302
308
continue ;
303
309
} else if arg. starts_with( concat!( $pat, "=" ) ) {
304
- if $ident . is_some( ) {
310
+ if $opt . is_some( ) {
305
311
return Err ( multi_arg( $help, subcommand. as_ref( ) ) ) ;
306
312
}
307
313
let next = arg
308
314
. splitn( 2 , '=' )
309
315
. nth( 1 )
310
316
. ok_or_else( || req_arg( $help, subcommand. as_ref( ) ) ) ?;
311
- $ident = Some ( next. to_string( ) ) ;
317
+ $opt = Some ( next. to_string( ) ) ;
312
318
if $propagate {
313
319
leading. push( arg) ;
314
320
}
@@ -317,18 +323,18 @@ pub(crate) fn args(coloring: &mut Option<Coloring>) -> Result<Option<Args>> {
317
323
} ;
318
324
}
319
325
320
- macro_rules! parse_arg2 {
321
- ( $ident : ident, $allow_split: expr, $pat: expr, $help: expr) => {
326
+ macro_rules! parse_multi_opt {
327
+ ( $v : ident, $allow_split: expr, $pat: expr, $help: expr) => {
322
328
if arg == $pat {
323
329
let arg = args. next( ) . ok_or_else( || req_arg( $help, subcommand. as_ref( ) ) ) ?;
324
330
if $allow_split {
325
331
if arg. contains( ',' ) {
326
- $ident . extend( arg. split( ',' ) . map( ToString :: to_string) ) ;
332
+ $v . extend( arg. split( ',' ) . map( ToString :: to_string) ) ;
327
333
} else {
328
- $ident . extend( arg. split( ' ' ) . map( ToString :: to_string) ) ;
334
+ $v . extend( arg. split( ' ' ) . map( ToString :: to_string) ) ;
329
335
}
330
336
} else {
331
- $ident . push( arg) ;
337
+ $v . push( arg) ;
332
338
}
333
339
continue ;
334
340
} else if arg. starts_with( concat!( $pat, "=" ) ) {
@@ -343,68 +349,49 @@ pub(crate) fn args(coloring: &mut Option<Coloring>) -> Result<Option<Args>> {
343
349
arg = & arg[ 1 ..arg. len( ) - 1 ] ;
344
350
}
345
351
if arg. contains( ',' ) {
346
- $ident . extend( arg. split( ',' ) . map( ToString :: to_string) ) ;
352
+ $v . extend( arg. split( ',' ) . map( ToString :: to_string) ) ;
347
353
} else {
348
- $ident . extend( arg. split( ' ' ) . map( ToString :: to_string) ) ;
354
+ $v . extend( arg. split( ' ' ) . map( ToString :: to_string) ) ;
349
355
}
350
356
} else {
351
- $ident . push( arg. to_string( ) ) ;
357
+ $v . push( arg. to_string( ) ) ;
352
358
}
353
359
continue ;
354
360
}
355
361
} ;
356
362
}
357
363
358
- parse_arg1 ! ( manifest_path, false , "--manifest-path" , "--manifest-path <PATH>" ) ;
359
- parse_arg1 ! ( color, true , "--color" , "--color <WHEN>" ) ;
364
+ macro_rules! parse_flag {
365
+ ( $flag: ident) => {
366
+ if mem:: replace( & mut $flag, true ) {
367
+ return Err ( multi_arg( & arg, subcommand. as_ref( ) ) ) ;
368
+ }
369
+ } ;
370
+ }
371
+
372
+ parse_opt ! ( manifest_path, false , "--manifest-path" , "--manifest-path <PATH>" ) ;
373
+ parse_opt ! ( color, true , "--color" , "--color <WHEN>" ) ;
360
374
361
- parse_arg2 ! ( package, false , "--package" , "--package <SPEC>" ) ;
362
- parse_arg2 ! ( package, false , "-p" , "--package <SPEC>" ) ;
363
- parse_arg2 ! ( exclude, false , "--exclude" , "--exclude <SPEC>" ) ;
364
- parse_arg2 ! ( features, true , "--features" , "--features <FEATURES>" ) ;
365
- parse_arg2 ! ( skip, true , "--skip" , "--skip <FEATURES>" ) ;
375
+ parse_multi_opt ! ( package, false , "--package" , "--package <SPEC>" ) ;
376
+ parse_multi_opt ! ( package, false , "-p" , "--package <SPEC>" ) ;
377
+ parse_multi_opt ! ( exclude, false , "--exclude" , "--exclude <SPEC>" ) ;
378
+ parse_multi_opt ! ( features, true , "--features" , "--features <FEATURES>" ) ;
379
+ parse_multi_opt ! ( skip, true , "--skip" , "--skip <FEATURES>" ) ;
366
380
367
381
match arg. as_str ( ) {
368
382
"--workspace" | "--all" => {
369
383
if let Some ( arg) = workspace. replace ( arg) {
370
384
return Err ( multi_arg ( & arg, subcommand. as_ref ( ) ) ) ;
371
385
}
372
386
}
373
- "--no-dev-deps" => {
374
- if mem:: replace ( & mut no_dev_deps, true ) {
375
- return Err ( multi_arg ( & arg, subcommand. as_ref ( ) ) ) ;
376
- }
377
- }
378
- "--remove-dev-deps" => {
379
- if mem:: replace ( & mut remove_dev_deps, true ) {
380
- return Err ( multi_arg ( & arg, subcommand. as_ref ( ) ) ) ;
381
- }
382
- }
383
- "--each-feature" => {
384
- if mem:: replace ( & mut each_feature, true ) {
385
- return Err ( multi_arg ( & arg, subcommand. as_ref ( ) ) ) ;
386
- }
387
- }
388
- "--feature-powerset" => {
389
- if mem:: replace ( & mut feature_powerset, true ) {
390
- return Err ( multi_arg ( & arg, subcommand. as_ref ( ) ) ) ;
391
- }
392
- }
393
- "--ignore-private" => {
394
- if mem:: replace ( & mut ignore_private, true ) {
395
- return Err ( multi_arg ( & arg, subcommand. as_ref ( ) ) ) ;
396
- }
397
- }
398
- "--optional-deps" => {
399
- if mem:: replace ( & mut optional_deps, true ) {
400
- return Err ( multi_arg ( & arg, subcommand. as_ref ( ) ) ) ;
401
- }
402
- }
403
- "--skip-no-default-features" => {
404
- if mem:: replace ( & mut skip_no_default_features, true ) {
405
- return Err ( multi_arg ( & arg, subcommand. as_ref ( ) ) ) ;
406
- }
407
- }
387
+ "--no-dev-deps" => parse_flag ! ( no_dev_deps) ,
388
+ "--remove-dev-deps" => parse_flag ! ( remove_dev_deps) ,
389
+ "--each-feature" => parse_flag ! ( each_feature) ,
390
+ "--feature-powerset" => parse_flag ! ( feature_powerset) ,
391
+ "--ignore-private" => parse_flag ! ( ignore_private) ,
392
+ "--optional-deps" => parse_flag ! ( optional_deps) ,
393
+ "--skip-no-default-features" => parse_flag ! ( skip_no_default_features) ,
394
+ "--clean-per-run" => parse_flag ! ( clean_per_run) ,
408
395
"--ignore-unknown-features" => {
409
396
if ignore_unknown_features || ignore_non_exist_features {
410
397
return Err ( multi_arg ( & arg, subcommand. as_ref ( ) ) ) ;
@@ -426,6 +413,7 @@ pub(crate) fn args(coloring: &mut Option<Coloring>) -> Result<Option<Args>> {
426
413
427
414
let color = color. map ( |c| c. parse ( ) ) . transpose ( ) ?;
428
415
* coloring = color;
416
+ let verbose = leading. iter ( ) . any ( |a| a == "--verbose" || a == "-v" || a == "-vv" ) ;
429
417
430
418
res?;
431
419
@@ -489,7 +477,7 @@ pub(crate) fn args(coloring: &mut Option<Coloring>) -> Result<Option<Args>> {
489
477
490
478
if subcommand. is_none ( ) {
491
479
if leading. iter ( ) . any ( |a| a == "--list" ) {
492
- let mut line = ProcessBuilder :: new ( crate :: cargo_binary ( ) ) ;
480
+ let mut line = ProcessBuilder :: new ( crate :: cargo_binary ( ) , verbose ) ;
493
481
line. arg ( "--list" ) ;
494
482
line. exec ( ) ?;
495
483
return Ok ( None ) ;
@@ -508,7 +496,6 @@ For more information try --help
508
496
}
509
497
}
510
498
511
- let verbose = leading. iter ( ) . any ( |a| a == "--verbose" || a == "-v" || a == "-vv" ) ;
512
499
if ignore_non_exist_features {
513
500
warn ! (
514
501
color,
@@ -542,6 +529,7 @@ For more information try --help
542
529
ignore_unknown_features : ignore_unknown_features || ignore_non_exist_features,
543
530
optional_deps,
544
531
skip_no_default_features,
532
+ clean_per_run,
545
533
546
534
features,
547
535
color,
0 commit comments