@@ -23,6 +23,13 @@ pub use clap::{value_parser, Arg, ArgAction, ArgMatches};
23
23
24
24
pub use clap:: Command ;
25
25
26
+ pub mod heading {
27
+ pub const PACKAGE_SELECTION : & str = "Package Selection" ;
28
+ pub const TARGET_SELECTION : & str = "Target Selection" ;
29
+ pub const FEATURE_SELECTION : & str = "Feature Selection" ;
30
+ pub const COMPILATION_OPTIONS : & str = "Compilation Options" ;
31
+ }
32
+
26
33
pub trait CommandExt : Sized {
27
34
fn _arg ( self , arg : Arg ) -> Self ;
28
35
@@ -34,8 +41,10 @@ pub trait CommandExt: Sized {
34
41
all : & ' static str ,
35
42
exclude : & ' static str ,
36
43
) -> Self {
37
- self . arg_package_spec_no_all ( package, all, exclude)
38
- . _arg ( flag ( "all" , "Alias for --workspace (deprecated)" ) )
44
+ self . arg_package_spec_no_all ( package, all, exclude) . _arg (
45
+ flag ( "all" , "Alias for --workspace (deprecated)" )
46
+ . help_heading ( heading:: PACKAGE_SELECTION ) ,
47
+ )
39
48
}
40
49
41
50
/// Variant of arg_package_spec that does not include the `--all` flag
@@ -48,19 +57,24 @@ pub trait CommandExt: Sized {
48
57
exclude : & ' static str ,
49
58
) -> Self {
50
59
self . arg_package_spec_simple ( package)
51
- . _arg ( flag ( "workspace" , all) )
52
- . _arg ( multi_opt ( "exclude" , "SPEC" , exclude) )
60
+ . _arg ( flag ( "workspace" , all) . help_heading ( heading :: PACKAGE_SELECTION ) )
61
+ . _arg ( multi_opt ( "exclude" , "SPEC" , exclude) . help_heading ( heading :: PACKAGE_SELECTION ) )
53
62
}
54
63
55
64
fn arg_package_spec_simple ( self , package : & ' static str ) -> Self {
56
- self . _arg ( optional_multi_opt ( "package" , "SPEC" , package) . short ( 'p' ) )
65
+ self . _arg (
66
+ optional_multi_opt ( "package" , "SPEC" , package)
67
+ . short ( 'p' )
68
+ . help_heading ( heading:: PACKAGE_SELECTION ) ,
69
+ )
57
70
}
58
71
59
72
fn arg_package ( self , package : & ' static str ) -> Self {
60
73
self . _arg (
61
74
optional_opt ( "package" , package)
62
75
. short ( 'p' )
63
- . value_name ( "SPEC" ) ,
76
+ . value_name ( "SPEC" )
77
+ . help_heading ( heading:: PACKAGE_SELECTION ) ,
64
78
)
65
79
}
66
80
@@ -91,11 +105,13 @@ pub trait CommandExt: Sized {
91
105
all : & ' static str ,
92
106
) -> Self {
93
107
self . arg_targets_lib_bin_example ( lib, bin, bins, example, examples)
94
- . _arg ( optional_multi_opt ( "test" , "NAME" , test) )
95
- . _arg ( flag ( "tests" , tests) )
96
- . _arg ( optional_multi_opt ( "bench" , "NAME" , bench) )
97
- . _arg ( flag ( "benches" , benches) )
98
- . _arg ( flag ( "all-targets" , all) )
108
+ . _arg ( optional_multi_opt ( "test" , "NAME" , test) . help_heading ( heading:: TARGET_SELECTION ) )
109
+ . _arg ( flag ( "tests" , tests) . help_heading ( heading:: TARGET_SELECTION ) )
110
+ . _arg (
111
+ optional_multi_opt ( "bench" , "NAME" , bench) . help_heading ( heading:: TARGET_SELECTION ) ,
112
+ )
113
+ . _arg ( flag ( "benches" , benches) . help_heading ( heading:: TARGET_SELECTION ) )
114
+ . _arg ( flag ( "all-targets" , all) . help_heading ( heading:: TARGET_SELECTION ) )
99
115
}
100
116
101
117
fn arg_targets_lib_bin_example (
@@ -106,11 +122,14 @@ pub trait CommandExt: Sized {
106
122
example : & ' static str ,
107
123
examples : & ' static str ,
108
124
) -> Self {
109
- self . _arg ( flag ( "lib" , lib) )
110
- . _arg ( optional_multi_opt ( "bin" , "NAME" , bin) )
111
- . _arg ( flag ( "bins" , bins) )
112
- . _arg ( optional_multi_opt ( "example" , "NAME" , example) )
113
- . _arg ( flag ( "examples" , examples) )
125
+ self . _arg ( flag ( "lib" , lib) . help_heading ( heading:: TARGET_SELECTION ) )
126
+ . _arg ( optional_multi_opt ( "bin" , "NAME" , bin) . help_heading ( heading:: TARGET_SELECTION ) )
127
+ . _arg ( flag ( "bins" , bins) . help_heading ( heading:: TARGET_SELECTION ) )
128
+ . _arg (
129
+ optional_multi_opt ( "example" , "NAME" , example)
130
+ . help_heading ( heading:: TARGET_SELECTION ) ,
131
+ )
132
+ . _arg ( flag ( "examples" , examples) . help_heading ( heading:: TARGET_SELECTION ) )
114
133
}
115
134
116
135
fn arg_targets_bins_examples (
@@ -120,15 +139,21 @@ pub trait CommandExt: Sized {
120
139
example : & ' static str ,
121
140
examples : & ' static str ,
122
141
) -> Self {
123
- self . _arg ( optional_multi_opt ( "bin" , "NAME" , bin) )
124
- . _arg ( flag ( "bins" , bins) )
125
- . _arg ( optional_multi_opt ( "example" , "NAME" , example) )
126
- . _arg ( flag ( "examples" , examples) )
142
+ self . _arg ( optional_multi_opt ( "bin" , "NAME" , bin) . help_heading ( heading:: TARGET_SELECTION ) )
143
+ . _arg ( flag ( "bins" , bins) . help_heading ( heading:: TARGET_SELECTION ) )
144
+ . _arg (
145
+ optional_multi_opt ( "example" , "NAME" , example)
146
+ . help_heading ( heading:: TARGET_SELECTION ) ,
147
+ )
148
+ . _arg ( flag ( "examples" , examples) . help_heading ( heading:: TARGET_SELECTION ) )
127
149
}
128
150
129
151
fn arg_targets_bin_example ( self , bin : & ' static str , example : & ' static str ) -> Self {
130
- self . _arg ( optional_multi_opt ( "bin" , "NAME" , bin) )
131
- . _arg ( optional_multi_opt ( "example" , "NAME" , example) )
152
+ self . _arg ( optional_multi_opt ( "bin" , "NAME" , bin) . help_heading ( heading:: TARGET_SELECTION ) )
153
+ . _arg (
154
+ optional_multi_opt ( "example" , "NAME" , example)
155
+ . help_heading ( heading:: TARGET_SELECTION ) ,
156
+ )
132
157
}
133
158
134
159
fn arg_features ( self ) -> Self {
@@ -138,34 +163,51 @@ pub trait CommandExt: Sized {
138
163
"FEATURES" ,
139
164
"Space or comma separated list of features to activate" ,
140
165
)
141
- . short ( 'F' ) ,
166
+ . short ( 'F' )
167
+ . help_heading ( heading:: FEATURE_SELECTION ) ,
168
+ )
169
+ . _arg (
170
+ flag ( "all-features" , "Activate all available features" )
171
+ . help_heading ( heading:: FEATURE_SELECTION ) ,
172
+ )
173
+ . _arg (
174
+ flag (
175
+ "no-default-features" ,
176
+ "Do not activate the `default` feature" ,
177
+ )
178
+ . help_heading ( heading:: FEATURE_SELECTION ) ,
142
179
)
143
- . _arg ( flag ( "all-features" , "Activate all available features" ) )
144
- . _arg ( flag (
145
- "no-default-features" ,
146
- "Do not activate the `default` feature" ,
147
- ) )
148
180
}
149
181
150
182
fn arg_release ( self , release : & ' static str ) -> Self {
151
- self . _arg ( flag ( "release" , release) . short ( 'r' ) )
183
+ self . _arg (
184
+ flag ( "release" , release)
185
+ . short ( 'r' )
186
+ . help_heading ( heading:: COMPILATION_OPTIONS ) ,
187
+ )
152
188
}
153
189
154
190
fn arg_profile ( self , profile : & ' static str ) -> Self {
155
- self . _arg ( opt ( "profile" , profile) . value_name ( "PROFILE-NAME" ) )
191
+ self . _arg (
192
+ opt ( "profile" , profile)
193
+ . value_name ( "PROFILE-NAME" )
194
+ . help_heading ( heading:: COMPILATION_OPTIONS ) ,
195
+ )
156
196
}
157
197
158
198
fn arg_doc ( self , doc : & ' static str ) -> Self {
159
199
self . _arg ( flag ( "doc" , doc) )
160
200
}
161
201
162
202
fn arg_target_triple ( self , target : & ' static str ) -> Self {
163
- self . _arg ( multi_opt ( "target" , "TRIPLE" , target) )
203
+ self . _arg ( multi_opt ( "target" , "TRIPLE" , target) . help_heading ( heading :: COMPILATION_OPTIONS ) )
164
204
}
165
205
166
206
fn arg_target_dir ( self ) -> Self {
167
207
self . _arg (
168
- opt ( "target-dir" , "Directory for all generated artifacts" ) . value_name ( "DIRECTORY" ) ,
208
+ opt ( "target-dir" , "Directory for all generated artifacts" )
209
+ . value_name ( "DIRECTORY" )
210
+ . help_heading ( heading:: COMPILATION_OPTIONS ) ,
169
211
)
170
212
}
171
213
0 commit comments