-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
261 lines (245 loc) · 9.04 KB
/
cli.js
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
import { config, extensions, download, repositories } from "./salt.js";
import { Command } from "commander";
import project from "./package.json" assert { type: "json" };
const program = new Command();
program
.name("salt")
.description("Get specified file from your repos.")
.version(project.version);
program
.command("download")
.aliases(["dl", "d", "get", "g"])
.description("Download a file.")
.argument("<File ID>", "The id of the file to download.")
.option("--ne, --no-extensions", "Don't use extensions.")
.action(async (fileID, options) => {
let file = await download(fileID, { noExtensions: options.ne });
});
program
.command("list")
.aliases(["ls", "l"])
.description("List all files in your repos.")
.action(async () => {
try {
const items = await repositories.getCachedListOfItems();
for (const item in items) {
if (Object.hasOwnProperty.call(items, item)) {
const itemData = items[item];
console.log(`${itemData.Name}:`);
console.log(` \x1b[34m id: ${item}\x1b[0m`);
console.log(` \x1b[32m url: ${itemData["URL"]}\x1b[0m`);
}
}
} catch (error) {
console.log("Listing items failed with error:" + error);
}
});
program
.command("list-repo")
.aliases(["list-repository", "listrepo", "listr", "lr"])
.description("List all files in a repo.")
.argument("<Repo ID>", "The id of the repo to list.")
.action(async (repoID) => {
const items = await repositories.getListOfItemsFromRepo(repoID);
for (const item in items) {
if (Object.hasOwnProperty.call(items, item)) {
const itemData = items[item];
console.log(`${itemData.Name}:`);
console.log(` \x1b[34m id: ${item}\x1b[0m`);
console.log(` \x1b[32m url: ${itemData["URL"]}\x1b[0m`);
}
}
});
program
.command("search")
.aliases(["s"])
.description("Search for files in your repos.")
.argument("<Search Query...>", "The query to search for.")
.action(async (searchQuery) => {
const repo = await repositories.getCachedListOfItems();
const idx = await repositories.search(searchQuery.join(" "));
idx.reverse();
for (const result of idx) {
let file = repo[result.ref];
console.log(`${file.Name}:`);
console.log(` \x1b[34m id: ${file.id}\x1b[0m`);
console.log(` \x1b[32m url: ${file["URL"]}\x1b[0m`);
}
});
program
.command("update")
.aliases(["u", "update-cache", "uc", "cache", "c", "cache-update", "cu"])
.description("Update the cache of your repos.")
.action(repositories.cacheRepos);
program
.command("repo-list")
.aliases(["repo", "r", "repolist", "rl", "list-repos", "listrepos"])
.description("List all repos.")
.action(async () => {
const repos = await repositories.getRepoList();
const repoNumber = Object.keys(repos).length;
let repoWord;
if (repoNumber == 1) {
repoWord = "repository";
} else {
repoWord = "repositories";
}
console.log(`You have ${repoNumber} ${repoWord}.`);
for (const repo in repos) {
if (Object.hasOwnProperty.call(repos, repo)) {
const repoData = repos[repo];
console.log(`${repoData.Name}:`);
console.log(` \x1b[34mid: ${repo}\x1b[0m`);
console.log(` \x1b[32murl: ${repoData["URL"]}\x1b[0m`);
}
}
});
program
.command("repo-add")
.aliases(["repoadd", "ra", "add-repo", "addrepo", "ar"])
.description("Add a repo to your list of repos.")
.argument("<Repo URL>", "The url of the repo to add.")
.action(repositories.addRepository);
program
.command("repo-remove")
.aliases(["reporemove", "rr", "remove-repo", "removerepo", "rr"])
.description("Remove a repo from your list of repos.")
.argument("<Repo ID>", "The id of the repo to remove.")
.action(repositories.removeRepository);
program
.command("extension-list")
.aliases([
"extension",
"extensionlist",
"el",
"list-extensions",
"listextensions",
])
.description("List all installed extensions.")
.action(async () => {
const extensions = await extensions.getExtensions();
for (const extension in extensions) {
if (Object.hasOwnProperty.call(extensions, extension)) {
const extensionData = extensions[extension];
console.log(`${extension}:`);
if (extensionData.downloadProtocols != null) {
console.log(" \x1b[34mDownload Protocols:\x1b[0m");
for (const downloadProtocol of extensionData.downloadProtocols) {
console.log(
` \x1b[34m${downloadProtocol}\x1b[0m`
);
}
}
if (extensionData.fileExtensions != null) {
console.log(
" \x1b[32mCompatible File Extensions:\x1b[0m"
);
for (const fileExtension of extensionData.fileExtensions) {
console.log(` \x1b[32m${fileExtension}\x1b[0m`);
}
}
if (extensionData.folderFiles != null) {
console.log(" \x1b[36mRequired RegExs:\x1b[0m");
for (const folderFile of extensionData.folderFiles) {
console.log(` \x1b[36m${folderFile}\x1b[0m`);
}
}
}
}
});
program
.command("extension-install")
.aliases([
"extensioninstall",
"ei",
"install-extension",
"installextension",
"ie",
])
.description("Install an extension.")
.argument("<Extension File>", "The file to install.")
.action(async (extensionFile) => {
await extensions.installExtension(extensionFile);
});
program
.command("extension-uninstall")
.aliases([
"extensionuninstall",
"eu",
"uninstall-extension",
"uninstallextension",
"ue",
])
.description("Uninstall an extension.")
.argument("<Extension ID>", "The id of the extension to uninstall.")
.action(async (extensionID) => {
await extensions.uninstallExtension(extensionID);
});
program
.command("config")
.aliases(["conf"])
.description("View or set properties in the config.")
.argument(
"<Config Property>",
"The property to print or set (outputDir, insecureConnections, or extensionsEnabled)."
)
.argument("[Config Value]", "The value to set the property to.")
.action(async (configProperty, configValue) => {
if (configValue != null) {
switch (configProperty) {
case "outputDir":
config.setOutputDir(configValue);
break;
case "insecureConnections":
if (
configValue == "true" ||
configValue == "t" ||
configValue == "yes" ||
configValue == "y"
) {
config.setInsecureConnections(true);
} else {
config.setInsecureConnections(false);
}
break;
case "extensionsEnabled":
config.setExtensionsEnabled(configValue);
break;
default:
console.log(
"Invalid config property. Valid properties are: outputDir, insecureConnections, and extensionsEnabled."
);
break;
}
} else {
switch (configProperty) {
case "outputDir":
console.log(`outputDir: ${config.getOutputDir()}`);
break;
case "insecureConnections":
console.log(
`insecureConnections: ${config.getInsecureConnections()}`
);
break;
case "extensionsEnabled":
console.log(
`extensionsEnabled: ${config.getExtensionsEnabled()}`
);
break;
default:
console.log(
"Invalid config property. Valid properties are: outputDir, insecureConnections, and extensionsEnabled."
);
break;
}
}
});
program
.command("get-uuid")
.aliases(["uuid", "gu"])
.description("Get the UUID of the current machine.")
.action(async () => {
const uuid = await config.getDeviceUUID();
console.log(uuid);
});
program.parse();