z_mirror/hare-fmm

git clone https://git.raiguard.me/z_mirror/hare-fmm

Caleb HeuerFinish -> free119b016

trunk
3.6 KiB136 linesraw
1use fmt;
2use getopt;
3
4fn clean(config: config, args: []str) void = {
5	const help: []getopt::help = [
6		"remove the given mods from the mods directory",
7		('a', "remove all non-symlink mods"),
8		"[mods...]"
9	];
10	let cmd = getopt::parse(args, help...);
11	if (len(cmd.args) == 0) {
12		abort_usage(args[0], help, "no argument was provided");
13	};
14	abort("clean subcommand is not yet implemented");
15};
16
17fn disable(config: config, args: []str) void = {
18	const help: []getopt::help = [
19		"disable the given mods, or all mods if none are given",
20		"[mods...]"
21	];
22	let cmd = getopt::parse(args, help...);
23	defer getopt::finish(&cmd);
24
25	// TODO: Error handling
26	let dir = dir_load(config.mods_dir)!;
27	defer dir_free(&dir);
28
29	if (len(cmd.args) == 0) {
30		dir_disable_all(&dir);
31	} else {
32		const mods = modident_parseall(&cmd.args, &config);
33		defer modident_free_all(mods);
34		dir_update_enabled(&dir, mods, false);
35	};
36
37	dir_save(&dir);
38};
39
40fn enable(config: config, args: []str) void = {
41	const help: []getopt::help = [
42		"enable the given mods",
43		"[mods...]"
44	];
45	let cmd = getopt::parse(args, help...);
46	defer getopt::finish(&cmd);
47	if (len(cmd.args) == 0) {
48		abort_usage(args[0], help, "no mods were provided");
49	};
50
51	let dir = match (dir_load(config.mods_dir)) {
52	case let dir: dir =>
53		yield dir;
54	case let err: dir_error =>
55		fmt::fatalf("Could not open mods directory at {}: {}",
56			config.mods_dir, dir_strerror(err));
57	};
58	defer dir_free(&dir);
59	const mods = modident_parseall(&cmd.args, &config);
60	defer modident_free_all(mods);
61	dir_update_enabled(&dir, mods, true);
62
63	dir_save(&dir);
64};
65
66fn install(config: config, args: []str) void = {
67	const help: []getopt::help = [
68		"install mods from the mod portal",
69		('d', "only download mods - do not change mod states"),
70		('f', "force install mods even if already present"),
71		"[mods...]"
72	];
73	let cmd = getopt::parse(args, help...);
74	if (len(cmd.args) == 0) {
75		abort_usage(args[0], help, "no mods were provided");
76	};
77	abort("install subcommand is not yet implemented");
78};
79
80fn query(config: config, args: []str) void = {
81	const help: []getopt::help = [
82		"search the local mods folder",
83		('d', "list dependencies"),
84		"<query>"
85	];
86	let cmd = getopt::parse(args, help...);
87	if (len(cmd.args) == 0) {
88		abort_usage(args[0], help, "no query was provided");
89	};
90	abort("query subcommand is not yet implemented");
91};
92
93fn sync(config: config, args: []str) void = {
94	const help: []getopt::help = [
95		"sync the state of the mods folder, installing mods if needed",
96		('f', "force download mods even if already present"),
97		('s', "do not sync mod startup settings"),
98		"<file | [mods...]>"
99	];
100	let cmd = getopt::parse(args, help...);
101	if (len(cmd.args) == 0) {
102		abort_usage(args[0], help, "no arguments were provided");
103	};
104	fmt::errorln("Note: sync subcommand onlys supports [mods...] right now")!;
105
106	let dir = match (dir_load(config.mods_dir)) {
107	case let dir: dir =>
108		yield dir;
109	case let err: dir_error =>
110		fmt::fatalf("Could not open mods directory at {}: {}",
111			config.mods_dir, dir_strerror(err));
112	};
113	defer dir_free(&dir);
114	dir_disable_all(&dir);
115	const mods = modident_parseall(&cmd.args, &config);
116	defer modident_free_all(mods);
117	dir_update_enabled(&dir, mods, true);
118
119	dir_save(&dir);
120};
121
122fn publish(config: config, args: []str) void = {
123	const help: []getopt::help = [
124		"publish a mod to the mod portal",
125		('d', "datestamp only"),
126		('u', "upload only - provide mod ZIP"),
127		('v', "increment version only"),
128		('z', "package only"),
129		"<file>"
130	];
131	let cmd = getopt::parse(args, help...);
132	if (len(cmd.args) == 0) {
133		abort_usage(args[0], help, "no argument was provided");
134	};
135	abort("publish subcommand is not yet implemented");
136};