-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathresources-ls.ts
More file actions
38 lines (30 loc) · 1.25 KB
/
resources-ls.ts
File metadata and controls
38 lines (30 loc) · 1.25 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
import { Command, Env } from "./lib/command.js";
import { stdout, stderr } from "process";
import { getDevice } from "./util.js";
const cmd = new Command("List available resources", {
action: async (options: Record<string, string | boolean>, args: Record<string, string>, env: Env) => {
const port = options["port"] as string;
const baudrate = options["baudrate"] as string;
const socket = options["socket"] as string;
const ble = options["ble"] as string | undefined;
const device = await getDevice(port, baudrate, socket, ble, env);
await device.controller.lock().catch((err) => {
stderr.write("Error locking device: " + err + "\n");
throw 1;
});
const listing = await device.uploader.listResources().catch((err) => {
stderr.write("Error: " + err + "\n");
throw 1;
});
stderr.write("Available resources:\n");
for (const [name, size] of listing) {
stdout.write(" " + name + " (" + size + " bytes)\n");
}
await device.controller.unlock().catch((err) => {
stderr.write("Error unlocking device: " + err + "\n");
throw 1;
});
},
chainable: true
});
export default cmd;