1use super::*;
2
3pub fn parse_args() -> Args {
9 let raw_args: Vec<String> = args().collect();
10 let mut command: CommandType = CommandType::Help;
11 let mut check: bool = false;
12 let mut manifest_path: Option<String> = None;
13 let mut bump_type: Option<BumpVersionType> = None;
14 let mut max_retries: u32 = 8;
15 let mut i: usize = 1;
16 while i < raw_args.len() {
17 let arg: &str = raw_args[i].as_str();
18 match arg {
19 "-h" | CLI_FLAG_HELP => {
20 command = CommandType::Help;
21 }
22 "-v" | CLI_FLAG_VERSION => {
23 command = CommandType::Version;
24 }
25 "fmt" if (command == CommandType::Help || command == CommandType::Version) => {
26 command = CommandType::Fmt;
27 }
28 CLI_BUMP if (command == CommandType::Help || command == CommandType::Version) => {
29 command = CommandType::Bump;
30 }
31 CLI_PUBLISH if (command == CommandType::Help || command == CommandType::Version) => {
32 command = CommandType::Publish;
33 }
34 CLI_SYNC if (command == CommandType::Help || command == CommandType::Version) => {
35 command = CommandType::Sync;
36 }
37 CLI_FLAG_PATCH => {
38 bump_type = Some(BumpVersionType::Patch);
39 }
40 CLI_FLAG_MINOR => {
41 bump_type = Some(BumpVersionType::Minor);
42 }
43 CLI_FLAG_MAJOR => {
44 bump_type = Some(BumpVersionType::Major);
45 }
46 CLI_FLAG_RELEASE => {
47 bump_type = Some(BumpVersionType::Release);
48 }
49 CLI_FLAG_ALPHA => {
50 bump_type = Some(BumpVersionType::Alpha);
51 }
52 CLI_FLAG_BETA => {
53 bump_type = Some(BumpVersionType::Beta);
54 }
55 CLI_FLAG_RC => {
56 bump_type = Some(BumpVersionType::Rc);
57 }
58 CLI_FLAG_CHECK => {
59 check = true;
60 }
61 CLI_FLAG_MANIFEST_PATH => {
62 i += 1;
63 if i < raw_args.len() {
64 manifest_path = Some(raw_args[i].clone());
65 }
66 }
67 CLI_FLAG_MAX_RETRIES => {
68 i += 1;
69 if i < raw_args.len()
70 && let Ok(n) = raw_args[i].parse::<u32>()
71 {
72 max_retries = n;
73 }
74 }
75 _ => {}
76 }
77 i += 1;
78 }
79 Args {
80 command,
81 check,
82 manifest_path,
83 bump_type,
84 max_retries,
85 }
86}