1
1
use crate :: command_prelude:: * ;
2
2
use anyhow:: { bail, format_err} ;
3
3
use cargo:: core:: dependency:: DepKind ;
4
- use cargo:: ops:: tree;
4
+ use cargo:: ops:: tree:: { self , EdgeKind } ;
5
5
use cargo:: util:: CargoResult ;
6
6
use std:: collections:: HashSet ;
7
7
use std:: str:: FromStr ;
@@ -32,12 +32,13 @@ pub fn cli() -> App {
32
32
. hidden ( true ) ,
33
33
)
34
34
. arg (
35
- opt (
36
- "dep-kinds" ,
37
- "Dependency kinds to display \
38
- (normal, build, dev, no-dev, no-build, no-normal, all)",
35
+ multi_opt (
36
+ "edges" ,
37
+ "KINDS" ,
38
+ "The kinds of dependencies to display \
39
+ (features, normal, build, dev, all, no-dev, no-build, no-normal)",
39
40
)
40
- . value_name ( "KINDS ") ,
41
+ . short ( "e ") ,
41
42
)
42
43
. arg ( opt ( "invert" , "Invert the tree direction" ) . short ( "i" ) )
43
44
. arg ( Arg :: with_name ( "no-indent" ) . long ( "no-indent" ) . hidden ( true ) )
@@ -79,7 +80,6 @@ pub fn cli() -> App {
79
80
. short ( "f" )
80
81
. default_value ( "{p}" ) ,
81
82
)
82
- . arg ( opt ( "graph-features" , "Include features in the tree" ) )
83
83
}
84
84
85
85
pub fn exec ( config : & mut Config , args : & ArgMatches < ' _ > ) -> CliResult {
@@ -116,15 +116,8 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
116
116
} ;
117
117
let target = tree:: Target :: from_cli ( target) ;
118
118
119
- let dep_kinds = if args. is_present ( "no-dev-dependencies" ) {
120
- config
121
- . shell ( )
122
- . warn ( "the --no-dev-dependencies flag has changed to --dep-kinds=no-dev" ) ?;
123
- Some ( "no-dev" )
124
- } else {
125
- args. value_of ( "dep-kinds" )
126
- } ;
127
- let dep_kinds = parse_dep_kinds ( dep_kinds) ?;
119
+ let edge_kinds = parse_edge_kinds ( config, args) ?;
120
+ let graph_features = edge_kinds. contains ( & EdgeKind :: Feature ) ;
128
121
129
122
let ws = args. workspace ( config) ?;
130
123
let charset = tree:: Charset :: from_str ( args. value_of ( "charset" ) . unwrap ( ) )
@@ -135,44 +128,57 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
135
128
no_default_features : args. is_present ( "no-default-features" ) ,
136
129
packages : args. packages_from_flags ( ) ?,
137
130
target,
138
- dep_kinds ,
131
+ edge_kinds ,
139
132
invert : args. is_present ( "invert" ) ,
140
133
prefix,
141
134
no_dedupe : args. is_present ( "no-dedupe" ) ,
142
135
duplicates : args. is_present ( "duplicates" ) ,
143
136
charset,
144
137
format : args. value_of ( "format" ) . unwrap ( ) . to_string ( ) ,
145
- graph_features : args . is_present ( "graph-features" ) ,
138
+ graph_features,
146
139
} ;
147
140
148
141
tree:: build_and_print ( & ws, & opts) ?;
149
142
Ok ( ( ) )
150
143
}
151
144
152
- fn parse_dep_kinds ( kinds : Option < & str > ) -> CargoResult < HashSet < DepKind > > {
153
- let kinds: Vec < & str > = kinds. unwrap_or ( "all" ) . split ( ',' ) . collect ( ) ;
145
+ fn parse_edge_kinds ( config : & Config , args : & ArgMatches < ' _ > ) -> CargoResult < HashSet < EdgeKind > > {
146
+ let mut kinds: Vec < & str > = args
147
+ . values_of ( "edges" )
148
+ . map_or_else ( || Vec :: new ( ) , |es| es. flat_map ( |e| e. split ( ',' ) ) . collect ( ) ) ;
149
+ if args. is_present ( "no-dev-dependencies" ) {
150
+ config
151
+ . shell ( )
152
+ . warn ( "the --no-dev-dependencies flag has changed to -e=no-dev" ) ?;
153
+ kinds. push ( "no-dev" ) ;
154
+ }
155
+ if kinds. len ( ) == 0 {
156
+ kinds. extend ( & [ "normal" , "build" , "dev" ] ) ;
157
+ }
158
+
154
159
let mut result = HashSet :: new ( ) ;
155
- let insert_all = |result : & mut HashSet < DepKind > | {
156
- result. insert ( DepKind :: Normal ) ;
157
- result. insert ( DepKind :: Build ) ;
158
- result. insert ( DepKind :: Development ) ;
160
+ let insert_defaults = |result : & mut HashSet < EdgeKind > | {
161
+ result. insert ( EdgeKind :: Dep ( DepKind :: Normal ) ) ;
162
+ result. insert ( EdgeKind :: Dep ( DepKind :: Build ) ) ;
163
+ result. insert ( EdgeKind :: Dep ( DepKind :: Development ) ) ;
159
164
} ;
160
165
let unknown = |k| {
161
166
bail ! (
162
- "unknown dependency kind `{}`, valid values are \
167
+ "unknown edge kind `{}`, valid values are \
163
168
\" normal\" , \" build\" , \" dev\" , \
164
169
\" no-normal\" , \" no-build\" , \" no-dev\" , \
165
- or \" all\" ",
170
+ \" features \" , or \" all\" ",
166
171
k
167
172
)
168
173
} ;
169
174
if kinds. iter ( ) . any ( |k| k. starts_with ( "no-" ) ) {
170
- insert_all ( & mut result) ;
175
+ insert_defaults ( & mut result) ;
171
176
for kind in & kinds {
172
177
match * kind {
173
- "no-normal" => result. remove ( & DepKind :: Normal ) ,
174
- "no-build" => result. remove ( & DepKind :: Build ) ,
175
- "no-dev" => result. remove ( & DepKind :: Development ) ,
178
+ "no-normal" => result. remove ( & EdgeKind :: Dep ( DepKind :: Normal ) ) ,
179
+ "no-build" => result. remove ( & EdgeKind :: Dep ( DepKind :: Build ) ) ,
180
+ "no-dev" => result. remove ( & EdgeKind :: Dep ( DepKind :: Development ) ) ,
181
+ "features" => result. insert ( EdgeKind :: Feature ) ,
176
182
"normal" | "build" | "dev" | "all" => {
177
183
bail ! ( "`no-` dependency kinds cannot be mixed with other dependency kinds" )
178
184
}
@@ -181,20 +187,29 @@ fn parse_dep_kinds(kinds: Option<&str>) -> CargoResult<HashSet<DepKind>> {
181
187
}
182
188
return Ok ( result) ;
183
189
}
184
- for kind in kinds {
185
- match kind {
186
- "all" => insert_all ( & mut result) ,
190
+ for kind in & kinds {
191
+ match * kind {
192
+ "all" => {
193
+ insert_defaults ( & mut result) ;
194
+ result. insert ( EdgeKind :: Feature ) ;
195
+ }
196
+ "features" => {
197
+ result. insert ( EdgeKind :: Feature ) ;
198
+ }
187
199
"normal" => {
188
- result. insert ( DepKind :: Normal ) ;
200
+ result. insert ( EdgeKind :: Dep ( DepKind :: Normal ) ) ;
189
201
}
190
202
"build" => {
191
- result. insert ( DepKind :: Build ) ;
203
+ result. insert ( EdgeKind :: Dep ( DepKind :: Build ) ) ;
192
204
}
193
205
"dev" => {
194
- result. insert ( DepKind :: Development ) ;
206
+ result. insert ( EdgeKind :: Dep ( DepKind :: Development ) ) ;
195
207
}
196
208
k => return unknown ( k) ,
197
209
}
198
210
}
211
+ if kinds. len ( ) == 1 && kinds[ 0 ] == "features" {
212
+ insert_defaults ( & mut result) ;
213
+ }
199
214
Ok ( result)
200
215
}
0 commit comments