-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
executable file
·79 lines (74 loc) · 1.81 KB
/
main.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
#!/usr/bin/env -S deno run --allow-all
/**
* DenoLCR - Deno Lite Clone of Rclone.
*
* ```shell
* ./main.js ls remote:path/to/folder/or/file
* ./main.js cat remote:path/to/file
* ./main.js check source:path dest:path
* ./main.js copy source:/path/to/file destination:/path/to/file
* ```
*/
import { argv, env, stdout } from "node:process";
import { parseArgs } from "./deps.js";
import * as commands from "./mod.js";
/** All optional params for the subcommand as an object. */
/**
* @type {Options}
*/
const options = {};
const {
_: [subcommand = "help", ...args],
// @ts-ignore - Deno.args is not typed.
} = parseArgs(argv.slice(2), {
alias: {
"progress": "P", // Show progress during transfer
},
boolean: [
"dry-run", // Do a trial run with no permanent changes
"human-readable", // Print numbers in a human-readable format, sizes with suffix Ki|Mi|Gi|Ti|Pi
"progress",
],
negatable: [
"progress",
],
string: [
"_",
"header",
"header-download",
"header-upload",
"transfers",
],
collect: [
"header",
"header-download",
"header-upload",
],
default: {
"dry-run": env["RCLONE_DRY_RUN"] === "true",
progress: env["RCLONE_PROGRESS"] === "true",
transfers: env["RCLONE_TRANSFERS"] || 4,
},
/**
* Collects other optional params
* @param {string} _arg
* @param {string} [key]
* @param {string} [value]
* @returns {boolean | void}
*/
unknown: (_arg, key, value) => {
if (key) { // key is the flag name
options[key.replace(/-/g, "_")] = `${value}`;
return false;
}
},
});
(async () => {
/** TODO merge global flags into config */
const response = await commands[subcommand](...args, options);
if (response.body) {
for await (const chunk of response.body) {
stdout.write(chunk);
}
}
})();