Skip to content

Commit a4641ab

Browse files
committed
feat(tree): Start completing --edges
1 parent ca352bc commit a4641ab

File tree

3 files changed

+68
-66
lines changed

3 files changed

+68
-66
lines changed

src/bin/cargo/commands/tree.rs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,21 @@ pub fn cli() -> Command {
2222
.arg_silent_suggestion()
2323
.arg(flag("no-dev-dependencies", "Deprecated, use -e=no-dev instead").hide(true))
2424
.arg(
25-
multi_opt(
26-
"edges",
27-
"KINDS",
28-
"The kinds of dependencies to display \
29-
(features, normal, build, dev, all, \
30-
no-normal, no-build, no-dev, no-proc-macro)",
31-
)
32-
.short('e')
33-
.value_delimiter(','),
25+
multi_opt("edges", "KINDS", "The kinds of dependencies to display")
26+
.short('e')
27+
.value_delimiter(',')
28+
.value_parser([
29+
"features",
30+
"normal",
31+
"build",
32+
"dev",
33+
"all",
34+
"public",
35+
"no-normal",
36+
"no-build",
37+
"no-dev",
38+
"no-proc-macro",
39+
]),
3440
)
3541
.arg(
3642
optional_multi_opt(
@@ -311,15 +317,6 @@ fn parse_edge_kinds(
311317
result.insert(EdgeKind::Dep(DepKind::Build));
312318
result.insert(EdgeKind::Dep(DepKind::Development));
313319
};
314-
let unknown = |k| {
315-
bail!(
316-
"unknown edge kind `{}`, valid values are \
317-
\"normal\", \"build\", \"dev\", \
318-
\"no-normal\", \"no-build\", \"no-dev\", \"no-proc-macro\", \
319-
\"features\", or \"all\"",
320-
k
321-
)
322-
};
323320
if kinds.iter().any(|k| k.starts_with("no-")) {
324321
insert_defaults(&mut result);
325322
for kind in &kinds {
@@ -336,7 +333,7 @@ fn parse_edge_kinds(
336333
kind
337334
)
338335
}
339-
k => return unknown(k),
336+
_ => unreachable!("`{kind}` was validated by clap"),
340337
};
341338
}
342339
return Ok((result, no_proc_macro, public));
@@ -359,7 +356,7 @@ fn parse_edge_kinds(
359356
"dev" => {
360357
result.insert(EdgeKind::Dep(DepKind::Development));
361358
}
362-
k => return unknown(k),
359+
_ => unreachable!("`{kind}` was validated by clap"),
363360
}
364361
}
365362
if kinds.len() == 1 && kinds[0] == "features" {

tests/testsuite/cargo_tree/deps.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,10 +1723,13 @@ fn unknown_edge_kind() {
17231723

17241724
p.cargo("tree -e unknown")
17251725
.with_stderr_data(str![[r#"
1726-
[ERROR] unknown edge kind `unknown`, valid values are "normal", "build", "dev", "no-normal", "no-build", "no-dev", "no-proc-macro", "features", or "all"
1726+
[ERROR] invalid value 'unknown' for '--edges <KINDS>'
1727+
[possible values: features, normal, build, dev, all, public, no-normal, no-build, no-dev, no-proc-macro]
1728+
1729+
For more information, try '--help'.
17271730
17281731
"#]])
1729-
.with_status(101)
1732+
.with_status(1)
17301733
.run();
17311734
}
17321735

tests/testsuite/cargo_tree/help/stdout.term.svg

Lines changed: 46 additions & 44 deletions
Loading

0 commit comments

Comments
 (0)