@@ -2,9 +2,9 @@ use std::{ffi::OsString, process::exit};
22
33use crate :: { prelude:: * , run:: run_benches} ;
44
5- use cargo:: util:: important_paths:: find_root_manifest_for_wd;
65use 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 } ;
88use termcolor:: Color ;
99
1010use crate :: build:: build_benches;
@@ -16,15 +16,30 @@ struct Cli {
1616 command : Commands ,
1717}
1818
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+
1933#[ derive( Subcommand ) ]
2034enum Commands {
2135 /// Build the benchmarks
2236 Build {
2337 /// Optional list of benchmarks to build (builds all benchmarks by default)
2438 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+
2843 /// Space or comma separated list of features to activate
2944 #[ arg( short = 'F' , long) ]
3045 features : Option < String > ,
@@ -33,9 +48,9 @@ enum Commands {
3348 Run {
3449 /// Optional list of benchmarks to run (run all found benchmarks by default)
3550 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 ,
3954 } ,
4055}
4156
@@ -50,27 +65,41 @@ pub fn run(args: impl Iterator<Item = OsString>) -> Result<()> {
5065 let cli = Cli :: try_parse_from ( args) ?;
5166 let cargo_config = get_cargo_config ( ) ?;
5267 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) ?;
5469
5570 let res = match cli. command {
5671 Commands :: Build {
5772 benches,
58- package ,
73+ package_selection ,
5974 features,
6075 } => {
6176 let features = features. map ( |f| {
6277 f. split ( |c| c == ' ' || c == ',' )
6378 . map ( |s| s. to_string ( ) )
6479 . collect_vec ( )
6580 } ) ;
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)
6798 }
68- Commands :: Run { benches, package } => run_benches ( & workspace, benches, package) ,
6999 } ;
70100
71101 if let Err ( e) = res {
72- workspace
73- . config ( )
102+ ws. config ( )
74103 . shell ( )
75104 . status_with_color ( "Error" , e. to_string ( ) , Color :: Red ) ?;
76105 exit ( 1 ) ;
0 commit comments