1use std::str::FromStr;
2
3pub enum ComponentType {
5 Perl,
7
8 NodeJS,
10}
11
12impl std::fmt::Display for ComponentType {
13 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
14 write!(
15 f,
16 "{}",
17 match self {
18 ComponentType::Perl => "perl",
19 ComponentType::NodeJS => "nodejs",
20 }
21 )
22 }
23}
24
25impl FromStr for ComponentType {
26 type Err = ();
27
28 fn from_str(s: &str) -> Result<Self, Self::Err> {
29 match s {
30 "perl" => Ok(ComponentType::Perl),
31 "nodejs" => Ok(ComponentType::NodeJS),
32 _ => Err(()),
33 }
34 }
35}
36
37#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
38pub enum Compression {
40 Gzip,
42
43 Xz,
45
46 Bzip2,
48
49 Lzma,
51
52 #[default]
53 Default,
55}
56
57impl std::fmt::Display for Compression {
58 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
59 write!(
60 f,
61 "{}",
62 match self {
63 Compression::Gzip => "gzip",
64 Compression::Xz => "xz",
65 Compression::Bzip2 => "bzip2",
66 Compression::Lzma => "lzma",
67 Compression::Default => "default",
68 }
69 )
70 }
71}
72
73impl FromStr for Compression {
74 type Err = ();
75
76 fn from_str(s: &str) -> Result<Self, Self::Err> {
77 match s {
78 "gz" | "gzip" => Ok(Compression::Gzip),
79 "xz" => Ok(Compression::Xz),
80 "bz2" | "bzip2" => Ok(Compression::Bzip2),
81 "lzma" => Ok(Compression::Lzma),
82 "default" => Ok(Compression::Default),
83 _ => Err(()),
84 }
85 }
86}
87
88#[derive(Debug, Clone, PartialEq, Eq, Hash)]
89pub enum Pretty {
91 Describe,
93
94 Pattern(String),
96}
97
98impl Default for Pretty {
99 fn default() -> Self {
100 Pretty::Pattern("0.0~git%cd.h%".to_string())
101 }
102}
103
104impl std::fmt::Display for Pretty {
105 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
106 write!(
107 f,
108 "{}",
109 match self {
110 Pretty::Describe => "describe",
111 Pretty::Pattern(pattern) => pattern,
112 }
113 )
114 }
115}
116
117impl FromStr for Pretty {
118 type Err = ();
119
120 fn from_str(s: &str) -> Result<Self, Self::Err> {
121 if s == "describe" {
122 Ok(Pretty::Describe)
123 } else {
124 Ok(Pretty::Pattern(s.to_string()))
125 }
126 }
127}
128
129#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
130pub enum GitExport {
132 #[default]
133 Default,
135
136 All,
139}
140
141impl std::fmt::Display for GitExport {
142 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
143 write!(
144 f,
145 "{}",
146 match self {
147 GitExport::Default => "default".to_string(),
148 GitExport::All => "all".to_string(),
149 }
150 )
151 }
152}
153
154impl FromStr for GitExport {
155 type Err = ();
156
157 fn from_str(s: &str) -> Result<Self, Self::Err> {
158 match s {
159 "default" => Ok(GitExport::Default),
160 "all" => Ok(GitExport::All),
161 _ => Err(()),
162 }
163 }
164}
165
166#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
167pub enum GitMode {
169 #[default]
170 Shallow,
172
173 Full,
175}
176
177impl std::fmt::Display for GitMode {
178 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
179 write!(
180 f,
181 "{}",
182 match self {
183 GitMode::Shallow => "shallow".to_string(),
184 GitMode::Full => "full".to_string(),
185 }
186 )
187 }
188}
189
190impl FromStr for GitMode {
191 type Err = ();
192
193 fn from_str(s: &str) -> Result<Self, Self::Err> {
194 match s {
195 "shallow" => Ok(GitMode::Shallow),
196 "full" => Ok(GitMode::Full),
197 _ => Err(()),
198 }
199 }
200}
201
202#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
203pub enum PgpMode {
205 Auto,
208
209 #[default]
210 Default,
217
218 Mangle,
220
221 Next,
224
225 Previous,
228
229 SelfSignature,
232
233 GitTag,
235}
236
237impl std::fmt::Display for PgpMode {
238 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
239 write!(
240 f,
241 "{}",
242 match self {
243 PgpMode::Auto => "auto",
244 PgpMode::Default => "default",
245 PgpMode::Mangle => "mangle",
246 PgpMode::Next => "next",
247 PgpMode::Previous => "previous",
248 PgpMode::SelfSignature => "self",
249 PgpMode::GitTag => "gittag",
250 }
251 )
252 }
253}
254impl FromStr for PgpMode {
255 type Err = ();
256
257 fn from_str(s: &str) -> Result<Self, Self::Err> {
258 match s {
259 "auto" => Ok(PgpMode::Auto),
260 "default" => Ok(PgpMode::Default),
261 "mangle" => Ok(PgpMode::Mangle),
262 "next" => Ok(PgpMode::Next),
263 "previous" => Ok(PgpMode::Previous),
264 "self" => Ok(PgpMode::SelfSignature),
265 "gittag" => Ok(PgpMode::GitTag),
266 _ => Err(()),
267 }
268 }
269}
270
271#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
272pub enum SearchMode {
274 #[default]
275 Html,
277
278 Plain,
280}
281
282impl std::fmt::Display for SearchMode {
283 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
284 write!(
285 f,
286 "{}",
287 match self {
288 SearchMode::Html => "html",
289 SearchMode::Plain => "plain",
290 }
291 )
292 }
293}
294
295impl FromStr for SearchMode {
296 type Err = ();
297
298 fn from_str(s: &str) -> Result<Self, Self::Err> {
299 match s {
300 "html" => Ok(SearchMode::Html),
301 "plain" => Ok(SearchMode::Plain),
302 _ => Err(()),
303 }
304 }
305}
306
307#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
308pub enum Mode {
310 #[default]
311 LWP,
314
315 Git,
318
319 Svn,
322}
323
324impl std::fmt::Display for Mode {
325 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
326 write!(
327 f,
328 "{}",
329 match self {
330 Mode::LWP => "lwp",
331 Mode::Git => "git",
332 Mode::Svn => "svn",
333 }
334 )
335 }
336}
337
338impl FromStr for Mode {
339 type Err = ();
340
341 fn from_str(s: &str) -> Result<Self, Self::Err> {
342 match s {
343 "lwp" => Ok(Mode::LWP),
344 "git" => Ok(Mode::Git),
345 "svn" => Ok(Mode::Svn),
346 _ => Err(()),
347 }
348 }
349}
350
351#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
352pub enum VersionPolicy {
354 #[default]
355 Debian,
357
358 Version(debversion::Version),
360
361 Same,
363
364 Previous,
366
367 Ignore,
369
370 Group,
373
374 Checksum,
379}
380
381impl std::fmt::Display for VersionPolicy {
382 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
383 match self {
384 VersionPolicy::Debian => write!(f, "debian"),
385 VersionPolicy::Version(v) => write!(f, "version-{}", v),
386 VersionPolicy::Same => write!(f, "same"),
387 VersionPolicy::Previous => write!(f, "previous"),
388 VersionPolicy::Ignore => write!(f, "ignore"),
389 VersionPolicy::Group => write!(f, "group"),
390 VersionPolicy::Checksum => write!(f, "checksum"),
391 }
392 }
393}
394
395impl std::str::FromStr for VersionPolicy {
396 type Err = String;
397
398 fn from_str(s: &str) -> Result<Self, Self::Err> {
399 match s {
400 "debian" => Ok(VersionPolicy::Debian),
401 "same" => Ok(VersionPolicy::Same),
402 "previous" => Ok(VersionPolicy::Previous),
403 "ignore" => Ok(VersionPolicy::Ignore),
404 "group" => Ok(VersionPolicy::Group),
405 "checksum" => Ok(VersionPolicy::Checksum),
406 s if s.starts_with("version-") => {
407 let v = s.trim_start_matches("version-");
408 Ok(VersionPolicy::Version(
409 v.parse::<debversion::Version>()
410 .map_err(|e| e.to_string())?,
411 ))
412 }
413 _ => Err(format!("Unknown version policy: {}", s)),
414 }
415 }
416}
417
418#[cfg(test)]
419mod version_policy_tests {
420 use super::VersionPolicy;
421 use std::str::FromStr;
422
423 #[test]
424 fn test_version_policy_to_string() {
425 assert_eq!("debian", VersionPolicy::Debian.to_string());
426 assert_eq!("same", VersionPolicy::Same.to_string());
427 assert_eq!("previous", VersionPolicy::Previous.to_string());
428 assert_eq!("ignore", VersionPolicy::Ignore.to_string());
429 assert_eq!("group", VersionPolicy::Group.to_string());
430 assert_eq!("checksum", VersionPolicy::Checksum.to_string());
431 assert_eq!(
432 "version-1.2.3",
433 VersionPolicy::Version("1.2.3".parse().unwrap()).to_string()
434 );
435 }
436
437 #[test]
438 fn test_version_policy_from_str() {
439 assert_eq!(
440 VersionPolicy::Debian,
441 VersionPolicy::from_str("debian").unwrap()
442 );
443 assert_eq!(
444 VersionPolicy::Same,
445 VersionPolicy::from_str("same").unwrap()
446 );
447 assert_eq!(
448 VersionPolicy::Previous,
449 VersionPolicy::from_str("previous").unwrap()
450 );
451 assert_eq!(
452 VersionPolicy::Ignore,
453 VersionPolicy::from_str("ignore").unwrap()
454 );
455 assert_eq!(
456 VersionPolicy::Group,
457 VersionPolicy::from_str("group").unwrap()
458 );
459 assert_eq!(
460 VersionPolicy::Checksum,
461 VersionPolicy::from_str("checksum").unwrap()
462 );
463 assert_eq!(
464 VersionPolicy::Version("1.2.3".parse().unwrap()),
465 VersionPolicy::from_str("version-1.2.3").unwrap()
466 );
467 }
468}