diff options
author | fxqnlr <[email protected]> | 2023-04-20 15:13:58 +0200 |
---|---|---|
committer | fxqnlr <[email protected]> | 2023-04-20 15:13:58 +0200 |
commit | 8050cfcd70a16273cc2814fe29c8ee08320d85d3 (patch) | |
tree | 13924a7f1a9a0c7515beb47a14fe62d5c387d09a /src/main.rs | |
parent | fde646a876cc43857a278ef09250263a21d547ee (diff) | |
download | modlist-8050cfcd70a16273cc2814fe29c8ee08320d85d3.tar modlist-8050cfcd70a16273cc2814fe29c8ee08320d85d3.tar.gz modlist-8050cfcd70a16273cc2814fe29c8ee08320d85d3.zip |
cargo fmt
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 115 |
1 files changed, 73 insertions, 42 deletions
diff --git a/src/main.rs b/src/main.rs index e845be1..eb5ee0b 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -1,5 +1,10 @@ | |||
1 | use clap::{Parser, Subcommand}; | 1 | use clap::{Parser, Subcommand}; |
2 | use modlist::{config::Cfg, mod_add, mod_remove, db::{lists_get, config_get_current_list, lists_get_all_ids}, IDSelector, download, update, List, get_current_list, import, devdir, export, list_add, Modloader, list_version, list_remove, list_change}; | 2 | use modlist::{ |
3 | config::Cfg, | ||
4 | db::{config_get_current_list, lists_get, lists_get_all_ids}, | ||
5 | devdir, download, export, get_current_list, import, list_add, list_change, list_remove, | ||
6 | list_version, mod_add, mod_remove, update, IDSelector, List, Modloader, | ||
7 | }; | ||
3 | 8 | ||
4 | //TODO make default list optional | 9 | //TODO make default list optional |
5 | #[derive(Parser)] | 10 | #[derive(Parser)] |
@@ -17,13 +22,13 @@ enum Commands { | |||
17 | }, | 22 | }, |
18 | List { | 23 | List { |
19 | #[command(subcommand)] | 24 | #[command(subcommand)] |
20 | command: ListCommands | 25 | command: ListCommands, |
21 | }, | 26 | }, |
22 | Download { | 27 | Download { |
23 | /// download all lists | 28 | /// download all lists |
24 | #[arg(short, long)] | 29 | #[arg(short, long)] |
25 | all: bool, | 30 | all: bool, |
26 | 31 | ||
27 | /// clean all mods before downloading them | 32 | /// clean all mods before downloading them |
28 | #[arg(short, long)] | 33 | #[arg(short, long)] |
29 | clean: bool, | 34 | clean: bool, |
@@ -36,11 +41,11 @@ enum Commands { | |||
36 | /// download all lists | 41 | /// download all lists |
37 | #[arg(short, long)] | 42 | #[arg(short, long)] |
38 | all: bool, | 43 | all: bool, |
39 | 44 | ||
40 | /// directly download updated mods | 45 | /// directly download updated mods |
41 | #[arg(short, long)] | 46 | #[arg(short, long)] |
42 | download: bool, | 47 | download: bool, |
43 | 48 | ||
44 | /// clean all mods before downloading them | 49 | /// clean all mods before downloading them |
45 | #[arg(short, long)] | 50 | #[arg(short, long)] |
46 | clean: bool, | 51 | clean: bool, |
@@ -59,7 +64,7 @@ enum Commands { | |||
59 | }, | 64 | }, |
60 | Export { | 65 | Export { |
61 | /// the list you want to export | 66 | /// the list you want to export |
62 | list: Option<String> | 67 | list: Option<String>, |
63 | }, | 68 | }, |
64 | } | 69 | } |
65 | 70 | ||
@@ -68,7 +73,7 @@ enum ModCommands { | |||
68 | Add { | 73 | Add { |
69 | /// id of the mod/version | 74 | /// id of the mod/version |
70 | id: String, | 75 | id: String, |
71 | 76 | ||
72 | /// set id mode to version | 77 | /// set id mode to version |
73 | #[arg(short, long)] | 78 | #[arg(short, long)] |
74 | version: bool, | 79 | version: bool, |
@@ -83,7 +88,7 @@ enum ModCommands { | |||
83 | 88 | ||
84 | /// optional List selection, else default list will be used | 89 | /// optional List selection, else default list will be used |
85 | #[arg(short, long)] | 90 | #[arg(short, long)] |
86 | list: Option<String> | 91 | list: Option<String>, |
87 | }, | 92 | }, |
88 | Remove { | 93 | Remove { |
89 | /// id, name or title of the mod | 94 | /// id, name or title of the mod |
@@ -91,8 +96,8 @@ enum ModCommands { | |||
91 | 96 | ||
92 | /// optional List selection, else default list will be used | 97 | /// optional List selection, else default list will be used |
93 | #[arg(short, long)] | 98 | #[arg(short, long)] |
94 | list: Option<String> | 99 | list: Option<String>, |
95 | } | 100 | }, |
96 | } | 101 | } |
97 | 102 | ||
98 | #[derive(Subcommand)] | 103 | #[derive(Subcommand)] |
@@ -109,12 +114,12 @@ enum ListCommands { | |||
109 | }, | 114 | }, |
110 | Remove { | 115 | Remove { |
111 | /// id, name or title of the list | 116 | /// id, name or title of the list |
112 | id: String | 117 | id: String, |
113 | }, | 118 | }, |
114 | List, | 119 | List, |
115 | Change { | 120 | Change { |
116 | /// id of the list to change to | 121 | /// id of the list to change to |
117 | id: String | 122 | id: String, |
118 | }, | 123 | }, |
119 | Version { | 124 | Version { |
120 | /// list id | 125 | /// list id |
@@ -129,12 +134,11 @@ enum ListCommands { | |||
129 | /// delete disabled versions | 134 | /// delete disabled versions |
130 | #[arg(short, long)] | 135 | #[arg(short, long)] |
131 | remove: bool, | 136 | remove: bool, |
132 | } | 137 | }, |
133 | } | 138 | } |
134 | 139 | ||
135 | #[tokio::main] | 140 | #[tokio::main] |
136 | async fn main() { | 141 | async fn main() { |
137 | |||
138 | let cli = Cli::parse(); | 142 | let cli = Cli::parse(); |
139 | 143 | ||
140 | let config = Cfg::init("modlist.toml").unwrap(); | 144 | let config = Cfg::init("modlist.toml").unwrap(); |
@@ -143,13 +147,22 @@ async fn main() { | |||
143 | //TODO setup? maybe setup on install | 147 | //TODO setup? maybe setup on install |
144 | match cli.command { | 148 | match cli.command { |
145 | Commands::Mod { command } => { | 149 | Commands::Mod { command } => { |
146 | |||
147 | match command { | 150 | match command { |
148 | #[allow(unused_variables)] | 151 | #[allow(unused_variables)] |
149 | ModCommands::Add { id, version, list, download, lock } => { | 152 | ModCommands::Add { |
153 | id, | ||
154 | version, | ||
155 | list, | ||
156 | download, | ||
157 | lock, | ||
158 | } => { | ||
150 | let listf = match list { | 159 | let listf = match list { |
151 | Some(list) => lists_get(config.clone(), list).unwrap(), | 160 | Some(list) => lists_get(config.clone(), list).unwrap(), |
152 | None => lists_get(config.clone(), config_get_current_list(config.clone()).unwrap()).unwrap(), | 161 | None => lists_get( |
162 | config.clone(), | ||
163 | config_get_current_list(config.clone()).unwrap(), | ||
164 | ) | ||
165 | .unwrap(), | ||
153 | }; | 166 | }; |
154 | 167 | ||
155 | let marked_id = match version { | 168 | let marked_id = match version { |
@@ -164,15 +177,24 @@ async fn main() { | |||
164 | //TODO add success even if no file found | 177 | //TODO add success even if no file found |
165 | let listf = match list { | 178 | let listf = match list { |
166 | Some(list) => lists_get(config.clone(), list).unwrap(), | 179 | Some(list) => lists_get(config.clone(), list).unwrap(), |
167 | None => lists_get(config.clone(), config_get_current_list(config.clone()).unwrap()).unwrap(), | 180 | None => lists_get( |
181 | config.clone(), | ||
182 | config_get_current_list(config.clone()).unwrap(), | ||
183 | ) | ||
184 | .unwrap(), | ||
168 | }; | 185 | }; |
169 | mod_remove(config, &id, listf) | 186 | mod_remove(config, &id, listf) |
170 | } | 187 | } |
171 | } | 188 | } |
172 | }, | 189 | } |
173 | Commands::List { command } => { | 190 | Commands::List { command } => { |
174 | match command { | 191 | match command { |
175 | ListCommands::Add { id, directory, modloader, version } => { | 192 | ListCommands::Add { |
193 | id, | ||
194 | directory, | ||
195 | modloader, | ||
196 | version, | ||
197 | } => { | ||
176 | let ml = match modloader { | 198 | let ml = match modloader { |
177 | Some(ml) => Modloader::from(&ml).unwrap(), | 199 | Some(ml) => Modloader::from(&ml).unwrap(), |
178 | //TODO add default modloader to config | 200 | //TODO add default modloader to config |
@@ -187,23 +209,27 @@ async fn main() { | |||
187 | }; | 209 | }; |
188 | 210 | ||
189 | list_add(config, id, ver, ml, directory) | 211 | list_add(config, id, ver, ml, directory) |
190 | }, | 212 | } |
191 | ListCommands::Remove { id } => { | 213 | ListCommands::Remove { id } => list_remove(config, id), |
192 | list_remove(config, id) | ||
193 | }, | ||
194 | ListCommands::List => { | 214 | ListCommands::List => { |
195 | todo!() | 215 | todo!() |
196 | }, | ||
197 | ListCommands::Change { id } => { | ||
198 | list_change(config, id) | ||
199 | }, | ||
200 | ListCommands::Version { id, version, download, remove } => { | ||
201 | list_version(config, id, version, download, remove).await | ||
202 | } | 216 | } |
217 | ListCommands::Change { id } => list_change(config, id), | ||
218 | ListCommands::Version { | ||
219 | id, | ||
220 | version, | ||
221 | download, | ||
222 | remove, | ||
223 | } => list_version(config, id, version, download, remove).await, | ||
203 | } | 224 | } |
204 | }, | 225 | } |
205 | //TODO a add specific list | 226 | //TODO a add specific list |
206 | Commands::Update { all, download, clean, remove } => { | 227 | Commands::Update { |
228 | all, | ||
229 | download, | ||
230 | clean, | ||
231 | remove, | ||
232 | } => { | ||
207 | let mut liststack: Vec<List> = vec![]; | 233 | let mut liststack: Vec<List> = vec![]; |
208 | if all { | 234 | if all { |
209 | let list_ids = lists_get_all_ids(config.clone()).unwrap(); | 235 | let list_ids = lists_get_all_ids(config.clone()).unwrap(); |
@@ -216,21 +242,26 @@ async fn main() { | |||
216 | liststack.push(current) | 242 | liststack.push(current) |
217 | } | 243 | } |
218 | update(config, liststack, clean, download, remove).await | 244 | update(config, liststack, clean, download, remove).await |
219 | }, | 245 | } |
220 | //TODO add specific list | 246 | //TODO add specific list |
221 | Commands::Download { all, clean, remove } => { | 247 | Commands::Download { all, clean, remove } => download(config, all, clean, remove).await, |
222 | download(config, all, clean, remove).await | ||
223 | }, | ||
224 | Commands::Import { file, download } => { | 248 | Commands::Import { file, download } => { |
225 | let filestr: String = match file { | 249 | let filestr: String = match file { |
226 | Some(args) => args, | 250 | Some(args) => args, |
227 | None => devdir(dirs::home_dir().unwrap().join("mlexport.toml").into_os_string().into_string().unwrap().as_str()), | 251 | None => devdir( |
252 | dirs::home_dir() | ||
253 | .unwrap() | ||
254 | .join("mlexport.toml") | ||
255 | .into_os_string() | ||
256 | .into_string() | ||
257 | .unwrap() | ||
258 | .as_str(), | ||
259 | ), | ||
228 | }; | 260 | }; |
229 | 261 | ||
230 | import(config, filestr, download).await | 262 | import(config, filestr, download).await |
231 | }, | 263 | } |
232 | Commands::Export { list } => { | 264 | Commands::Export { list } => export(config, list), |
233 | export(config, list) | 265 | } |
234 | }, | 266 | .unwrap(); |
235 | }.unwrap(); | ||
236 | } | 267 | } |