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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
use std::{
path::{Path, PathBuf},
str::FromStr,
};
use anyhow::{anyhow, Result};
use structopt::StructOpt;
use crate::git;
#[derive(StructOpt)]
#[structopt(bin_name = "cargo")]
pub enum Cli {
#[structopt(name = "generate", visible_alias = "gen")]
Generate(Args),
}
#[derive(Debug, StructOpt)]
pub struct Args {
#[structopt(
long,
conflicts_with = "git",
conflicts_with = "subfolder",
conflicts_with = "path",
conflicts_with = "branch",
conflicts_with = "name",
conflicts_with = "force",
conflicts_with = "template_values_file",
conflicts_with = "silent",
conflicts_with = "vcs",
conflicts_with = "lib",
conflicts_with = "bin",
conflicts_with = "ssh_identity",
conflicts_with = "define",
conflicts_with = "init"
)]
pub list_favorites: bool,
#[structopt(name = "favorite|git|subfolder")]
pub favorite: Option<String>,
#[structopt()]
pub subfolder: Option<String>,
#[structopt(short, long, conflicts_with = "subfolder")]
pub git: Option<String>,
#[structopt(
short,
long,
conflicts_with = "git",
conflicts_with = "favorite",
conflicts_with = "subfolder"
)]
pub path: Option<PathBuf>,
#[structopt(short, long)]
pub branch: Option<String>,
#[structopt(long, short)]
pub name: Option<String>,
#[structopt(long, short)]
pub force: bool,
#[structopt(long, short)]
pub verbose: bool,
#[structopt(long)]
pub template_values_file: Option<String>,
#[structopt(long, short, requires("name"))]
pub silent: bool,
#[structopt(short, long, parse(from_os_str))]
pub config: Option<PathBuf>,
#[structopt(long, default_value = "git")]
pub vcs: Vcs,
#[structopt(long, conflicts_with = "bin")]
pub lib: bool,
#[structopt(long, conflicts_with = "lib")]
pub bin: bool,
#[structopt(short = "i", long = "identity", parse(from_os_str))]
pub ssh_identity: Option<PathBuf>,
#[structopt(long, short, number_of_values = 1)]
pub define: Vec<String>,
#[structopt(long)]
pub init: bool,
}
#[derive(Debug, StructOpt, Clone, Copy)]
pub enum Vcs {
None,
Git,
}
impl FromStr for Vcs {
type Err = anyhow::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_uppercase().as_str() {
"NONE" => Ok(Vcs::None),
"GIT" => Ok(Vcs::Git),
_ => Err(anyhow!("Must be one of 'git' or 'none'")),
}
}
}
impl Vcs {
pub fn initialize(&self, project_dir: &Path, branch: String) -> Result<()> {
match self {
Vcs::None => {}
Vcs::Git => {
git::init(project_dir, &branch)?;
}
};
Ok(())
}
}