Skip to content
This repository was archived by the owner on Nov 15, 2024. It is now read-only.

Commit 09329cb

Browse files
committed
Add handlers for devices and locks
1 parent 48a876f commit 09329cb

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed

src/cli/commands/devices.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import executeCommand from "../execute-command"
2+
import { YargsWithGlobalOptions } from "../global-options"
3+
4+
export default {
5+
command: "devices",
6+
aliases: ["device"],
7+
describe: "interact with devices",
8+
builder: (yargs: YargsWithGlobalOptions) => {
9+
yargs
10+
.demandCommand()
11+
.command(
12+
"get <id>",
13+
"get a device",
14+
(yargs) => {
15+
return yargs.positional("id", {
16+
describe: "the device ID",
17+
demandOption: true,
18+
})
19+
},
20+
async (argv) => {
21+
await executeCommand("devices.get", [argv.id], argv)
22+
}
23+
)
24+
.command(
25+
"list",
26+
"list devices",
27+
(yargs) => {
28+
return yargs.option("connected-account-id", {
29+
describe: "filter by connected account ID",
30+
type: "string",
31+
alias: "ca",
32+
})
33+
},
34+
async (argv) => {
35+
await executeCommand("devices.list", [argv.connectedAccountId], argv)
36+
}
37+
)
38+
},
39+
}

src/cli/commands/locks.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import executeCommand from "../execute-command"
2+
import { YargsWithGlobalOptions } from "../global-options"
3+
4+
export default {
5+
command: "locks",
6+
aliases: ["lock"],
7+
describe: "interact with locks",
8+
builder: (yargs: YargsWithGlobalOptions) => {
9+
yargs
10+
.demandCommand()
11+
.command(
12+
"get <id>",
13+
"get a lock",
14+
(yargs) => {
15+
return yargs.positional("id", {
16+
describe: "the lock ID",
17+
demandOption: true,
18+
})
19+
},
20+
async (argv) => {
21+
await executeCommand("locks.get", [argv.id], argv)
22+
}
23+
)
24+
.command(
25+
"list",
26+
"list locks",
27+
(yargs) => {
28+
return yargs.option("connected-account-id", {
29+
describe: "filter by connected account ID",
30+
type: "string",
31+
alias: "ca",
32+
})
33+
},
34+
async (argv) => {
35+
await executeCommand("locks.list", [argv.connectedAccountId], argv)
36+
}
37+
)
38+
.command(
39+
"lock-door <id>",
40+
"lock a door",
41+
(yargs) => {
42+
return yargs.positional("id", {
43+
describe: "the lock ID",
44+
demandOption: true,
45+
})
46+
},
47+
async (argv) => {
48+
await executeCommand("locks.lockDoor", [argv.id], argv)
49+
}
50+
)
51+
.command(
52+
"unlock-door <id>",
53+
"unlock a door",
54+
(yargs) => {
55+
return yargs.positional("id", {
56+
describe: "the lock ID",
57+
demandOption: true,
58+
})
59+
},
60+
async (argv) => {
61+
await executeCommand("locks.unlockDoor", [argv.id], argv)
62+
}
63+
)
64+
},
65+
}

src/cli/execute-command.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import ora from "ora"
22
import { paramCase } from "change-case"
33
import Seam, { SeamAPIError } from ".."
44

5+
// todo: tighten types for args
56
const executeCommand = async (
67
methodName: string,
78
args: any[],

0 commit comments

Comments
 (0)