-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
80 lines (73 loc) · 2.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
const { program } = require("commander");
const jta = require("./joplin-to-anki");
const configStore = require("./config");
const { levelApplication, levelVerbose, levelDebug } = require("./log");
program.version("0.0.0");
program
.option(
"-t, --joplintoken <token>",
"token for Joplin Web Clipper API",
configStore.get("joplinToken")
)
.option(
"-d, --date <ISO Time String>",
"joplin notes updated after this date will be exported. Defaults to configured value or now - 1 day",
configStore.getWithFallback("exportFromDate")
)
.option(
"-j, --joplinurl <URL>",
"URL for Joplin Web Clipper API",
configStore.getWithFallback("joplinURL")
)
.option(
"-a, --ankiurl <URL>",
"URL for Anki Connect API",
configStore.getWithFallback("ankiURL")
)
.option(
`-l, --loglevel <one of ${levelApplication}, ${levelVerbose}, ${levelDebug}>`,
"Enable verbose logs",
levelApplication
);
program
.command("run")
.description("export from Joplin to Anki")
.requiredOption(
"-t, --joplintoken <token>",
"token for Joplin Web Clipper API",
configStore.get("joplinToken")
)
.action(async () => {
const now = new Date().toISOString();
await jta.run(
program.loglevel,
program.joplinurl,
program.joplintoken,
program.date,
program.ankiurl
);
configStore.set("exportFromDate", now);
});
const config = program.command("config").description("Get/set configs for JTA");
config
.command("set")
.description(
"Set options in config; these options will be used as default by JTA"
)
.action(() => {
configStore.set("joplinURL", program.joplinurl);
configStore.set("ankiURL", program.ankiurl);
configStore.set("joplinToken", program.joplintoken);
configStore.set("exportFromDate", program.date);
console.log(configStore.getAll());
});
config
.command("get")
.description("Get options in config")
.action(() => {
console.log(configStore.getAll());
});
function cli(args) {
program.parse(args);
}
module.exports = cli;