-
Notifications
You must be signed in to change notification settings - Fork 4
/
tg.js
executable file
·68 lines (64 loc) · 2.45 KB
/
tg.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
#!/usr/bin/env -S deno run --allow-all --unstable --import-map ./import_map.json
import {Command, EnumType} from "https://deno.land/x/cliffy/command/mod.ts";
import {TwingateApiClient} from "./TwingateApiClient.mjs";
import {Log, LOG_LEVELS} from "./utils/log.js";
import {
exportCmd,
removeAllCmd,
importCmd,
removeDuplicateResourceCmd,
scriptCmd,
getTopLevelCommand,
} from "./cliCmd/cmd.mjs";
import * as Colors from "https://deno.land/std/fmt/colors.ts";
import {deployCmd} from "./cliCmd/deploy/index.mjs";
import {VERSION} from "./version.js";
async function main(args) {
const topLevelCommands = ["resource", "group", "user", "network", "connector", "device", "service", "policy"];
const LogLevelType = new EnumType(Object.keys(LOG_LEVELS));
let cmd = new Command()
.name("tg")
.version(`CLI Version: ${VERSION} | TwingateApiClient Version: ${TwingateApiClient.VERSION}`)
.description("CLI for Twingate")
.type("LogLevel", LogLevelType)
.option("-a, --account-name <string>", "Twingate account name", {
global: true,
default: Deno.env.get("TG_ACCOUNT")
})
.option("-l, --log-level [logLevel:LogLevel]", "Log level", {
global: true,
//hidden: true,
default: Deno.env.get("LOG_LEVEL") || "INFO",
action: (options) => Deno.env.set("LOG_LEVEL", options.logLevel)
})
.action(async (options) => {
Log.success(`This is the Twingate CLI tool, ${Colors.italic('tg')}`);
` __
_/ |_ ____
\\ __\\/ ___\\
| | / /_/ >
|__| \\___ /
/_____/
`.split("\n").map(Log.info);
Log.info(`No parameters specified, please try:`);
Log.info(Colors.italic(`tg --help`));
Log.info(`For a list of possible commands.`);
Log.info("");
Log.info(`For assistance with this tool please visit https://github.com/twingate-labs/tg-cli`);
return 0;
})
.command("export", exportCmd)
.command("import", importCmd)
.command("remove-duplicate-resource", removeDuplicateResourceCmd)
.command("remove-all", removeAllCmd)
.command("script", scriptCmd)
.command("deploy", deployCmd)
;
for ( const command of topLevelCommands ) cmd = cmd.command(command, getTopLevelCommand(command));
return await cmd.parse(args);
}
try {
await main(Deno.args);
} catch (e) {
Log.exception(e);
}