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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
use anyhow::Result;
use clap::Args;
use std::{
convert::TryFrom,
fmt,
};
#[derive(Default, Clone, Debug, Args)]
pub struct VerbosityFlags {
#[clap(long)]
quiet: bool,
#[clap(long)]
verbose: bool,
}
impl TryFrom<&VerbosityFlags> for Verbosity {
type Error = anyhow::Error;
fn try_from(value: &VerbosityFlags) -> Result<Self, Self::Error> {
match (value.quiet, value.verbose) {
(false, false) => Ok(Verbosity::Default),
(true, false) => Ok(Verbosity::Quiet),
(false, true) => Ok(Verbosity::Verbose),
(true, true) => anyhow::bail!("Cannot pass both --quiet and --verbose flags"),
}
}
}
#[derive(Clone, Copy, Default, serde::Serialize, Eq, PartialEq)]
pub enum Verbosity {
#[default]
Default,
Quiet,
Verbose,
}
impl Verbosity {
pub fn is_verbose(&self) -> bool {
match self {
Verbosity::Quiet => false,
Verbosity::Default | Verbosity::Verbose => true,
}
}
}
#[derive(Eq, PartialEq, Copy, Clone, Debug, Default, serde::Serialize)]
pub enum Network {
#[default]
Online,
Offline,
}
impl Network {
pub fn append_to_args(&self, args: &mut Vec<String>) {
match self {
Self::Online => (),
Self::Offline => args.push("--offline".to_owned()),
}
}
}
#[derive(
Copy, Clone, Default, Eq, PartialEq, Debug, clap::ValueEnum, serde::Serialize,
)]
#[clap(name = "build-artifacts")]
pub enum BuildArtifacts {
#[clap(name = "all")]
#[default]
All,
#[clap(name = "code-only")]
CodeOnly,
#[clap(name = "check-only")]
CheckOnly,
}
impl BuildArtifacts {
pub fn steps(&self) -> usize {
match self {
BuildArtifacts::All => 5,
BuildArtifacts::CodeOnly => 4,
BuildArtifacts::CheckOnly => 1,
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct BuildSteps {
pub current_step: usize,
pub total_steps: Option<usize>,
}
impl BuildSteps {
pub fn new() -> Self {
Self {
current_step: 1,
total_steps: None,
}
}
pub fn increment_current(&mut self) {
self.current_step += 1;
}
pub fn set_total_steps(&mut self, steps: usize) {
self.total_steps = Some(steps)
}
}
impl Default for BuildSteps {
fn default() -> Self {
Self::new()
}
}
impl fmt::Display for BuildSteps {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let total_steps = self
.total_steps
.map_or("*".to_string(), |steps| steps.to_string());
write!(f, "[{}/{}]", self.current_step, total_steps)
}
}
#[derive(
Eq, PartialEq, Copy, Clone, Debug, Default, serde::Serialize, serde::Deserialize,
)]
pub enum BuildMode {
#[default]
Debug,
Release,
}
impl fmt::Display for BuildMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Debug => write!(f, "debug"),
Self::Release => write!(f, "release"),
}
}
}
#[derive(Clone, Debug, Default)]
pub enum OutputType {
#[default]
HumanReadable,
Json,
}
#[derive(Default, Clone, Debug, Args)]
pub struct UnstableOptions {
#[clap(long = "unstable-options", short = 'Z', number_of_values = 1)]
options: Vec<String>,
}
#[derive(Clone, Default)]
pub struct UnstableFlags {
pub original_manifest: bool,
}
impl TryFrom<&UnstableOptions> for UnstableFlags {
type Error = anyhow::Error;
fn try_from(value: &UnstableOptions) -> Result<Self, Self::Error> {
let valid_flags = ["original-manifest"];
let invalid_flags = value
.options
.iter()
.filter(|o| !valid_flags.contains(&o.as_str()))
.collect::<Vec<_>>();
if !invalid_flags.is_empty() {
anyhow::bail!("Unknown unstable-options {:?}", invalid_flags)
}
Ok(UnstableFlags {
original_manifest: value.options.contains(&"original-manifest".to_owned()),
})
}
}
#[derive(Default, Clone, Debug, Args)]
pub struct Features {
#[clap(long, value_delimiter = ',')]
features: Vec<String>,
}
impl Features {
pub fn push(&mut self, feature: &str) {
self.features.push(feature.to_owned())
}
pub fn append_to_args(&self, args: &mut Vec<String>) {
if !self.features.is_empty() {
args.push("--features".to_string());
let features = if self.features.len() == 1 {
self.features[0].clone()
} else {
self.features.join(",")
};
args.push(features);
}
}
}