-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.js
More file actions
executable file
·78 lines (72 loc) · 1.56 KB
/
main.js
File metadata and controls
executable file
·78 lines (72 loc) · 1.56 KB
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
#!/usr/bin/env -S deno run --allow-all
/**
* rfetch - fetching between remotes
*
* ```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 "node:util";
import * as commands from "./mod.js";
/** Optional params for the subcommand. */
const options = {
"dry-run": {
type: "boolean",
default: env["RCLONE_DRY_RUN"] === "true",
},
"header": {
type: "string",
multiple: true,
},
"header-download": {
type: "string",
multiple: true,
},
"header-upload": {
type: "string",
multiple: true,
},
"human-readable": {
type: "boolean",
},
"progress": {
type: "boolean",
short: "P",
default: env["RCLONE_PROGRESS"] === "true",
},
"transfers": {
type: "string",
default: env["RCLONE_TRANSFERS"] || "4",
}
};
const {
values: flags,
positionals: [
subcommand = "help",
...args
],
} = parseArgs({
args: argv.slice(2),
options,
strict: false,
allowPositionals: true,
allowNegative: true,
tokens: true,
});
for (const name of Object.keys(flags)) {
// Adds snake_case version of the flag.
flags[name.replace(/-/g, "_")] = flags[name];
}
(async () => {
/** TODO merge global flags into config */
const response = await commands[subcommand](...args, flags);
if (response.body) {
for await (const chunk of response.body) {
stdout.write(chunk);
}
}
})();