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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
use std::{
path::{Path, PathBuf},
str::FromStr,
};
use anyhow::{anyhow, Result};
use clap::Parser;
use crate::git;
#[derive(Parser)]
#[clap(bin_name = "cargo")]
pub enum Cli {
#[clap(name = "generate", visible_alias = "gen")]
Generate(Args),
}
#[derive(Clone, Debug, Parser)]
pub struct Args {
#[clap(
long,
action,
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,
#[clap(name = "favorite", value_parser)]
pub favorite: Option<String>,
#[clap(name = "subfolder", value_parser)]
pub subfolder: Option<String>,
#[clap(name = "git", short, long, value_parser, conflicts_with = "subfolder")]
pub git: Option<String>,
#[clap(
short,
long,
value_parser,
conflicts_with = "git",
conflicts_with = "favorite",
conflicts_with = "subfolder"
)]
pub path: Option<PathBuf>,
#[clap(short, long, value_parser)]
pub branch: Option<String>,
#[clap(long, short, value_parser)]
pub name: Option<String>,
#[clap(long, short, action)]
pub force: bool,
#[clap(long, short, action)]
pub verbose: bool,
#[clap(long, value_parser)]
pub template_values_file: Option<String>,
#[clap(long, short, requires("name"), action)]
pub silent: bool,
#[clap(short, long, value_parser)]
pub config: Option<PathBuf>,
#[clap(long, default_value = "git", value_parser)]
pub vcs: Vcs,
#[clap(long, conflicts_with = "bin", action)]
pub lib: bool,
#[clap(long, conflicts_with = "lib", action)]
pub bin: bool,
#[clap(short = 'i', long = "identity", value_parser)]
pub ssh_identity: Option<PathBuf>,
#[clap(long, short, number_of_values = 1, value_parser)]
pub define: Vec<String>,
#[clap(long, conflicts_with = "destination", action)]
pub init: bool,
#[clap(long, conflicts_with = "init", value_parser)]
pub destination: Option<PathBuf>,
#[clap(long, action)]
pub force_git_init: bool,
#[clap(short, long, action)]
pub allow_commands: bool,
}
#[derive(Debug, Parser, 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(Self::None),
"GIT" => Ok(Self::Git),
_ => Err(anyhow!("Must be one of 'git' or 'none'")),
}
}
}
impl Vcs {
pub fn initialize(&self, project_dir: &Path, branch: String, force: bool) -> Result<()> {
match self {
Self::None => Ok(()),
Self::Git => git::init(project_dir, &branch, force)
.map(|_| ())
.map_err(anyhow::Error::from),
}
}
pub const fn is_none(&self) -> bool {
matches!(self, Self::None)
}
}