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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
use clap::{Parser, Subcommand};
use modlist::{
config::Cfg,
db::{config_get_current_list, lists_get, lists_get_all_ids},
download, export, get_current_list, import, list_add, list_change, list_remove, list_version,
mod_add, mod_remove, update, IDSelector, List, Modloader, VersionLevel, list_list, AddMod,
};
#[derive(Parser)]
#[command(author, version, about)]
struct Cli {
#[command(subcommand)]
command: Commands,
/// config file path
#[arg(short, long)]
config: Option<String>,
/// Force GameVersion update
#[arg(long)]
force_gameupdate: bool,
}
#[derive(Subcommand)]
enum Commands {
r#Mod {
#[command(subcommand)]
command: ModCommands,
},
List {
#[command(subcommand)]
command: ListCommands,
},
Download {
/// download all lists
#[arg(short, long)]
all: bool,
/// clean all mods before downloading them
#[arg(short, long)]
clean: bool,
/// remove disabled versions
#[arg(short, long)]
remove: bool,
/// optional List selection, else default list will be used
#[arg(short, long)]
list: Option<String>,
},
Update {
/// download all lists
#[arg(short, long)]
all: bool,
/// directly download updated mods
#[arg(short, long)]
download: bool,
/// clean all mods before downloading them
#[arg(short, long)]
clean: bool,
/// delete disabled versions
#[arg(short, long)]
remove: bool,
/// optional List selection, else default list will be used
#[arg(short, long)]
list: Option<String>,
},
Import {
#[arg(short, long)]
file: Option<String>,
/// directly download imported mods
#[arg(short, long)]
download: bool,
},
Export {
/// the list you want to export
list: Option<String>,
},
Test
}
#[derive(Subcommand)]
enum ModCommands {
Add {
/// id of the mod/version
id: String,
/// set id mode to version
#[arg(short, long)]
version: bool,
/// directly download the mod
#[arg(short, long)]
download: bool,
/// lock the version added
#[arg(/* short , */long)]
lock: bool,
/// optional List selection, else default list will be used
#[arg(short, long)]
list: Option<String>,
},
Remove {
/// id, name or title of the mod
id: String,
/// optional List selection, else default list will be used
#[arg(short, long)]
list: Option<String>,
},
}
#[derive(Subcommand)]
enum ListCommands {
Add {
/// list id
id: String,
directory: String,
modloader: Option<String>,
version: Option<String>,
},
Remove {
/// id, name or title of the list
id: String,
},
List,
Change {
/// id of the list to change to
id: String,
},
Version {
/// list id
id: String,
/// desired minecraft version
version: String,
/// directly download updated mods
#[arg(long, short)]
download: bool,
/// delete disabled versions
#[arg(short, long)]
remove: bool,
},
}
#[tokio::main]
async fn main() {
let cli = Cli::parse();
let config = Cfg::init(cli.config).await.unwrap();
match cli.command {
Commands::Mod { command } => {
match command {
#[allow(unused_variables)]
ModCommands::Add {
id,
version,
list,
download,
lock,
} => {
let listf = match list {
Some(list) => lists_get(config.clone(), list).unwrap(),
None => lists_get(
config.clone(),
config_get_current_list(config.clone()).unwrap(),
)
.unwrap(),
};
let marked_id = match version {
true => IDSelector::VersionID(id),
false => IDSelector::ModificationID(id),
};
let add_id = AddMod { id: marked_id, set_version: lock };
mod_add(config, vec![add_id], listf, download).await
}
ModCommands::Remove { id, list } => {
let listf = match list {
Some(list) => lists_get(config.clone(), list).unwrap(),
None => lists_get(
config.clone(),
config_get_current_list(config.clone()).unwrap(),
)
.unwrap(),
};
mod_remove(config, &id, listf)
}
}
}
Commands::List { command } => {
match command {
ListCommands::Add {
id,
directory,
modloader,
version,
} => {
let ml = match modloader {
Some(ml) => Modloader::from(&ml).unwrap(),
None => config.clone().defaults.modloader,
};
let versions_path = &config.versions;
let ver = match version {
Some(ver) => VersionLevel::from(&ver).get(versions_path, cli.force_gameupdate).await.unwrap(),
None => config.clone().defaults.version.get(versions_path, cli.force_gameupdate).await.unwrap(),
};
list_add(config, id, ver, ml, directory)
}
ListCommands::Remove { id } => list_remove(config, id),
ListCommands::List => {
list_list(config)
}
ListCommands::Change { id } => list_change(config, id),
ListCommands::Version {
id,
version,
download,
remove,
} => list_version(config, id, version, download, remove).await,
}
}
Commands::Update {
all,
download,
clean,
remove,
list
} => {
let mut liststack: Vec<List> = vec![];
if all {
let list_ids = lists_get_all_ids(config.clone()).unwrap();
for id in list_ids {
liststack.push(lists_get(config.clone(), id).unwrap());
}
} else {
let current = match list {
Some(l) => lists_get(config.clone(), l).unwrap(),
None => get_current_list(config.clone()).unwrap(),
};
liststack.push(current)
}
update(config, liststack, clean, download, remove).await
}
Commands::Download { all, clean, remove, list } => {
let mut liststack: Vec<List> = vec![];
if all {
let list_ids = lists_get_all_ids(config.clone()).unwrap();
for id in list_ids {
liststack.push(lists_get(config.clone(), id).unwrap());
}
} else {
let current = match list {
Some(l) => lists_get(config.clone(), l).unwrap(),
None => get_current_list(config.clone()).unwrap(),
};
liststack.push(current)
}
download(config, liststack, clean, remove).await
},
Commands::Import { file, download } => {
let filestr: String = match file {
Some(args) => args,
None => dirs::home_dir()
.unwrap()
.join("mlexport.toml")
.into_os_string()
.into_string()
.unwrap(),
};
import(config, filestr, download).await
}
Commands::Export { list } => export(config, list),
Commands::Test => Ok(()),
}
.unwrap();
}
|