-
Notifications
You must be signed in to change notification settings - Fork 152
/
Copy pathgroup.rs
51 lines (48 loc) · 1.35 KB
/
group.rs
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
//! How to use `clap::Arg::group`
//!
//! Running this example with --help prints this message:
//! -----------------------------------------------------
//! structopt 0.3.25
//!
//! USAGE:
//! group [OPTIONS] <--method <method>|--get|--head|--post|--put|--delete>
//!
//! FLAGS:
//! --delete HTTP DELETE
//! --get HTTP GET
//! -h, --help Prints help information
//! --head HTTP HEAD
//! --post HTTP POST
//! --put HTTP PUT
//! -V, --version Prints version information
//!
//! OPTIONS:
//! --method <method> Set a custom HTTP verb
//! -----------------------------------------------------
use structopt::{clap::ArgGroup, StructOpt};
#[derive(StructOpt, Debug)]
#[structopt(group = ArgGroup::with_name("verb").required(true))]
struct Opt {
/// Set a custom HTTP verb
#[structopt(long, group = "verb")]
method: Option<String>,
/// HTTP GET
#[structopt(long, group = "verb")]
get: bool,
/// HTTP HEAD
#[structopt(long, group = "verb")]
head: bool,
/// HTTP POST
#[structopt(long, group = "verb")]
post: bool,
/// HTTP PUT
#[structopt(long, group = "verb")]
put: bool,
/// HTTP DELETE
#[structopt(long, group = "verb")]
delete: bool,
}
fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}