diff options
Diffstat (limited to 'src/input.rs')
-rw-r--r-- | src/input.rs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/input.rs b/src/input.rs index b2b4f1b..41b0c29 100644 --- a/src/input.rs +++ b/src/input.rs | |||
@@ -11,6 +11,7 @@ pub struct Input { | |||
11 | pub delete_old: bool, | 11 | pub delete_old: bool, |
12 | pub clean: bool, | 12 | pub clean: bool, |
13 | pub disable_download: bool, | 13 | pub disable_download: bool, |
14 | pub version: bool, | ||
14 | } | 15 | } |
15 | 16 | ||
16 | impl Input { | 17 | impl Input { |
@@ -22,6 +23,7 @@ impl Input { | |||
22 | let mut delete_old = false; | 23 | let mut delete_old = false; |
23 | let mut clean = false; | 24 | let mut clean = false; |
24 | let mut disable_download = false; | 25 | let mut disable_download = false; |
26 | let mut version = false; | ||
25 | 27 | ||
26 | let mut toremove: Vec<usize> = vec![]; | 28 | let mut toremove: Vec<usize> = vec![]; |
27 | for (i, input) in split.clone().into_iter().enumerate() { | 29 | for (i, input) in split.clone().into_iter().enumerate() { |
@@ -32,6 +34,7 @@ impl Input { | |||
32 | "--delete-old" => delete_old = true, | 34 | "--delete-old" => delete_old = true, |
33 | "--clean" => clean = true, | 35 | "--clean" => clean = true, |
34 | "--disable-download" => disable_download = true, | 36 | "--disable-download" => disable_download = true, |
37 | "--version" => version = true, | ||
35 | _ => continue, | 38 | _ => continue, |
36 | } | 39 | } |
37 | toremove.push(i) | 40 | toremove.push(i) |
@@ -41,6 +44,11 @@ impl Input { | |||
41 | for rem in toremove.into_iter().rev() { | 44 | for rem in toremove.into_iter().rev() { |
42 | split.remove(rem); | 45 | split.remove(rem); |
43 | } | 46 | } |
47 | |||
48 | if version { | ||
49 | println!("Modlist by FxQnLr v{}", env!("CARGO_PKG_VERSION")); | ||
50 | std::process::exit(0); | ||
51 | } | ||
44 | 52 | ||
45 | let command = Cmd::from(split.remove(0))?; | 53 | let command = Cmd::from(split.remove(0))?; |
46 | let subcommand = match split.is_empty() { | 54 | let subcommand = match split.is_empty() { |
@@ -59,7 +67,7 @@ impl Input { | |||
59 | } | 67 | } |
60 | }; | 68 | }; |
61 | 69 | ||
62 | Ok(Self { command, subcommand, args, direct_download, all_lists, delete_old, clean, disable_download }) | 70 | Ok(Self { command, subcommand, args, direct_download, all_lists, delete_old, clean, disable_download, version }) |
63 | } | 71 | } |
64 | } | 72 | } |
65 | 73 | ||
@@ -110,7 +118,7 @@ pub async fn get_input(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { | |||
110 | args.reverse(); | 118 | args.reverse(); |
111 | args.pop(); | 119 | args.pop(); |
112 | args.reverse(); | 120 | args.reverse(); |
113 | 121 | ||
114 | let input = Input::from(&args.join(" "))?; | 122 | let input = Input::from(&args.join(" "))?; |
115 | 123 | ||
116 | match input.command { | 124 | match input.command { |
@@ -135,11 +143,10 @@ pub async fn get_input(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { | |||
135 | #[test] | 143 | #[test] |
136 | fn input_from() { | 144 | fn input_from() { |
137 | let string = "list add test 1.19.2 fabric"; | 145 | let string = "list add test 1.19.2 fabric"; |
138 | let input = Input{ command: Cmd::List, subcommand: Some(Subcmd::Add), args: Some(vec![String::from("test"), String::from("1.19.2"), String::from("fabric")]), direct_download: false, all_lists: false, clean: false, delete_old: false, disable_download: false }; | 146 | let input = Input{ command: Cmd::List, subcommand: Some(Subcmd::Add), args: Some(vec![String::from("test"), String::from("1.19.2"), String::from("fabric")]), direct_download: false, all_lists: false, clean: false, delete_old: false, disable_download: false, version: false }; |
139 | assert_eq!(Input::from(string).unwrap(), input); | 147 | assert_eq!(Input::from(string).unwrap(), input); |
140 | 148 | ||
141 | let string = "update --direct-download --delete-old"; | 149 | let string = "update --direct-download --delete-old"; |
142 | let input = Input{ command: Cmd::Update, subcommand: None, args: None, direct_download: true, all_lists: false, clean: false, delete_old: true, disable_download: false }; | 150 | let input = Input{ command: Cmd::Update, subcommand: None, args: None, direct_download: true, all_lists: false, clean: false, delete_old: true, disable_download: false, version: false }; |
143 | assert_eq!(Input::from(string).unwrap(), input); | 151 | assert_eq!(Input::from(string).unwrap(), input); |
144 | |||
145 | } | 152 | } |