1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
// https://github.com/TeXitoi/structopt/issues/151
// https://github.com/TeXitoi/structopt/issues/289
#[test]
fn issue_151() {
use structopt::{clap::ArgGroup, StructOpt};
#[derive(StructOpt, Debug)]
#[structopt(group = ArgGroup::with_name("verb").required(true).multiple(true))]
struct Opt {
#[structopt(long, group = "verb")]
foo: bool,
#[structopt(long, group = "verb")]
bar: bool,
}
#[derive(Debug, StructOpt)]
struct Cli {
#[structopt(flatten)]
a: Opt,
}
assert!(Cli::clap().get_matches_from_safe(&["test"]).is_err());
assert!(Cli::clap()
.get_matches_from_safe(&["test", "--foo"])
.is_ok());
assert!(Cli::clap()
.get_matches_from_safe(&["test", "--bar"])
.is_ok());
assert!(Cli::clap()
.get_matches_from_safe(&["test", "--zebra"])
.is_err());
assert!(Cli::clap()
.get_matches_from_safe(&["test", "--foo", "--bar"])
.is_ok());
}
#[test]
fn issue_289() {
use structopt::{clap::AppSettings, StructOpt};
#[derive(StructOpt)]
#[structopt(setting = AppSettings::InferSubcommands)]
enum Args {
SomeCommand(SubSubCommand),
AnotherCommand,
}
#[derive(StructOpt)]
#[structopt(setting = AppSettings::InferSubcommands)]
enum SubSubCommand {
TestCommand,
}
assert!(Args::clap()
.get_matches_from_safe(&["test", "some-command", "test-command"])
.is_ok());
assert!(Args::clap()
.get_matches_from_safe(&["test", "some", "test-command"])
.is_ok());
assert!(Args::clap()
.get_matches_from_safe(&["test", "some-command", "test"])
.is_ok());
assert!(Args::clap()
.get_matches_from_safe(&["test", "some", "test"])
.is_ok());
}
|