-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.ts
More file actions
142 lines (122 loc) · 4.17 KB
/
index.ts
File metadata and controls
142 lines (122 loc) · 4.17 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
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
#!/usr/bin/env node
import { Opt, Arg, Command, Program } from "./lib/command.js";
import { logger } from "../util/logger.js";
import { stdout, stderr } from "process";
const jac = new Program("jac", "Tools for controlling devices running Jaculus", {
globalOptions: {
"log-level": new Opt("Set log level", { defaultValue: "info" }),
"help": new Opt("Print this help message", { isFlag: true }),
"port": new Opt("Serial port to use (default: first available)"),
"baudrate": new Opt("Baudrate to use", { defaultValue: "921600" }),
"socket": new Opt("host:port to use"),
"ble": new Opt("Bluetooth LE address to use", { defaultValue: undefined }),
},
action: async (options: Record<string, string | boolean>) => {
if (options["help"]) {
stdout.write(jac.help() + "\n");
throw 0;
}
logger.level = options["log-level"] as string;
}
});
jac.addCommand("help", new Command("Print help for given command", {
action: async (options: Record<string, string | boolean>, args: Record<string, string>) => {
const command = args["command"];
if (command) {
const cmd = jac.getCommand(command);
if (cmd) {
stdout.write(cmd.help(command) + "\n");
}
else {
stdout.write(`Unknown command: ${command}` + "\n");
}
}
else {
stdout.write(jac.help() + "\n");
}
},
args: [
new Arg("command", "The command to get help for", { required: false }),
],
}));
import listPorts from "./list-ports.js";
import serialSocket from "./serial-socket.js";
import install from "./install.js";
import build from "./build.js";
import flash from "./flash.js";
import ls from "./ls.js";
import read from "./read.js";
import write from "./write.js";
import rm from "./rm.js";
import mkdir from "./mkdir.js";
import rmdir from "./rmdir.js";
import upload from "./upload.js";
import start from "./start.js";
import stop from "./stop.js";
import status from "./status.js";
import version from "./version.js";
import monitor from "./monitor.js";
import pull from "./pull.js";
import fomat from "./format.js";
import resourcesLs from "./resources-ls.js";
import resourcesRead from "./resources-read.js";
import getExamples from "./get-examples.js";
import listBle from "./list-ble.js";
import { wifiAdd, wifiRemove, wifiGet, wifiSetAp, wifiSetSta, wifiDisable } from "./wifi.js";
import { bleGet, bleDisable, bleEnableStream, bleSetName} from "./ble.js";
jac.addCommand("list-ports", listPorts);
jac.addCommand("list-ble", listBle);
jac.addCommand("serial-socket", serialSocket);
jac.addCommand("install", install);
jac.addCommand("build", build);
jac.addCommand("flash", flash);
jac.addCommand("pull", pull);
jac.addCommand("ls", ls);
jac.addCommand("read", read);
jac.addCommand("write", write);
jac.addCommand("rm", rm);
jac.addCommand("mkdir", mkdir);
jac.addCommand("rmdir", rmdir);
jac.addCommand("upload", upload);
jac.addCommand("format", fomat);
jac.addCommand("resources-ls", resourcesLs);
jac.addCommand("resources-read", resourcesRead);
jac.addCommand("get-examples", getExamples);
jac.addCommand("start", start);
jac.addCommand("stop", stop);
jac.addCommand("status", status);
jac.addCommand("version", version);
jac.addCommand("monitor", monitor);
jac.addCommand("wifi-get", wifiGet);
jac.addCommand("wifi-ap", wifiSetAp);
jac.addCommand("wifi-add", wifiAdd);
jac.addCommand("wifi-rm", wifiRemove);
jac.addCommand("wifi-sta", wifiSetSta);
jac.addCommand("wifi-disable", wifiDisable);
jac.addCommand("ble-get", bleGet);
jac.addCommand("ble-disable", bleDisable);
jac.addCommand("ble-enable-stream", bleEnableStream);
jac.addCommand("ble-set-name", bleSetName);
const args = process.argv.slice(2);
if (args.length === 0) {
args.push("help");
}
jac.run(args).then(() => {
jac.end();
stderr.write("\nDone\n");
process.exit(0);
}
).catch((e) => {
jac.end();
if (typeof e === "number") {
process.exit(e);
}
else if (e instanceof Error) {
console.error(e.message);
process.exit(1);
}
else {
console.error(e);
process.exit(1);
}
});