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
68
69
70
71
72
73
74
75
76
77
78
79
80
use failure::format_err;
use failure::Error;
use source_uri::SourceUri;
use std::path::PathBuf;
use std::str::FromStr;
use structopt::StructOpt;
#[derive(StructOpt, Debug, Default, Clone)]
#[structopt(
raw(setting = "structopt::clap::AppSettings::ColoredHelp"),
author = "davidB"
)]
pub struct CmdOpt {
#[structopt(short = "v", long = "verbose", parse(from_occurrences))]
pub verbose: usize,
#[structopt(long = "confirm", default_value = "never")]
pub confirm: AskConfirmation,
#[structopt(long = "x-always_default_value")]
pub x_always_default_value: bool,
#[structopt(long = "offline")]
pub offline: bool,
#[structopt(short = "s", long = "source",)]
pub src_uri: SourceUri,
#[structopt(long = "rev", default_value = "master")]
pub src_rev: String,
#[structopt(long = "source-folder", parse(from_os_str))]
pub src_folder: Option<PathBuf>,
#[structopt(
short = "d",
long = "destination",
parse(from_os_str),
)]
pub dst_folder: PathBuf,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AskConfirmation {
Auto,
Always,
Never,
}
impl FromStr for AskConfirmation {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"never" => Ok(AskConfirmation::Never),
"always" => Ok(AskConfirmation::Always),
"auto" => Ok(AskConfirmation::Auto),
_ => Err(format_err!(
"should be 'never', 'always' or 'auto' (default)"
)),
}
}
}
impl Default for AskConfirmation {
fn default() -> Self {
AskConfirmation::Auto
}
}