@@ -2,9 +2,9 @@ use std::{ffi::OsString, process::exit};
2
2
3
3
use crate :: { prelude:: * , run:: run_benches} ;
4
4
5
- use cargo:: util:: important_paths:: find_root_manifest_for_wd;
6
5
use cargo:: Config ;
7
- use clap:: { Parser , Subcommand } ;
6
+ use cargo:: { ops:: Packages , util:: important_paths:: find_root_manifest_for_wd} ;
7
+ use clap:: { Args , Parser , Subcommand } ;
8
8
use termcolor:: Color ;
9
9
10
10
use crate :: build:: build_benches;
@@ -16,15 +16,30 @@ struct Cli {
16
16
command : Commands ,
17
17
}
18
18
19
+ /// Package selection flags
20
+ #[ derive( Args ) ]
21
+ struct PackageSelection {
22
+ /// Select all packages in the workspace
23
+ #[ arg( long) ]
24
+ workspace : bool ,
25
+ /// Exclude packages
26
+ #[ arg( long) ]
27
+ exclude : Vec < String > ,
28
+ /// Package to select
29
+ #[ arg( short, long) ]
30
+ package : Vec < String > ,
31
+ }
32
+
19
33
#[ derive( Subcommand ) ]
20
34
enum Commands {
21
35
/// Build the benchmarks
22
36
Build {
23
37
/// Optional list of benchmarks to build (builds all benchmarks by default)
24
38
benches : Option < Vec < String > > ,
25
- /// Package to build benchmarks for (if using a workspace)
26
- #[ arg( short, long) ]
27
- package : Option < String > ,
39
+
40
+ #[ command( flatten) ]
41
+ package_selection : PackageSelection ,
42
+
28
43
/// Space or comma separated list of features to activate
29
44
#[ arg( short = 'F' , long) ]
30
45
features : Option < String > ,
@@ -33,9 +48,9 @@ enum Commands {
33
48
Run {
34
49
/// Optional list of benchmarks to run (run all found benchmarks by default)
35
50
benches : Option < Vec < String > > ,
36
- /// Package to build benchmarks for (if using a workspace)
37
- #[ arg ( short , long ) ]
38
- package : Option < String > ,
51
+
52
+ #[ command ( flatten ) ]
53
+ package_selection : PackageSelection ,
39
54
} ,
40
55
}
41
56
@@ -50,27 +65,41 @@ pub fn run(args: impl Iterator<Item = OsString>) -> Result<()> {
50
65
let cli = Cli :: try_parse_from ( args) ?;
51
66
let cargo_config = get_cargo_config ( ) ?;
52
67
let manifest_path = find_root_manifest_for_wd ( cargo_config. cwd ( ) ) ?;
53
- let workspace = Workspace :: new ( & manifest_path, & cargo_config) ?;
68
+ let ws = Workspace :: new ( & manifest_path, & cargo_config) ?;
54
69
55
70
let res = match cli. command {
56
71
Commands :: Build {
57
72
benches,
58
- package ,
73
+ package_selection ,
59
74
features,
60
75
} => {
61
76
let features = features. map ( |f| {
62
77
f. split ( |c| c == ' ' || c == ',' )
63
78
. map ( |s| s. to_string ( ) )
64
79
. collect_vec ( )
65
80
} ) ;
66
- build_benches ( & workspace, benches, package, features)
81
+ let packages = Packages :: from_flags (
82
+ package_selection. workspace ,
83
+ package_selection. exclude ,
84
+ package_selection. package ,
85
+ ) ?;
86
+ build_benches ( & ws, benches, packages, features)
87
+ }
88
+ Commands :: Run {
89
+ benches,
90
+ package_selection,
91
+ } => {
92
+ let packages = Packages :: from_flags (
93
+ package_selection. workspace ,
94
+ package_selection. exclude ,
95
+ package_selection. package ,
96
+ ) ?;
97
+ run_benches ( & ws, benches, packages)
67
98
}
68
- Commands :: Run { benches, package } => run_benches ( & workspace, benches, package) ,
69
99
} ;
70
100
71
101
if let Err ( e) = res {
72
- workspace
73
- . config ( )
102
+ ws. config ( )
74
103
. shell ( )
75
104
. status_with_color ( "Error" , e. to_string ( ) , Color :: Red ) ?;
76
105
exit ( 1 ) ;
0 commit comments