-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
executable file
·44 lines (33 loc) · 1.1 KB
/
index.ts
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
#!/usr/bin/env tsx
import { env } from 'node:process'
import landlubber, {
type DefaultContext,
defaultMiddleware,
type EmptyOptions,
type Handler as DefaultHandler,
type MiddlewareFunction,
} from 'landlubber'
import { Seam } from 'seam'
import * as device from './device.js'
import * as devices from './devices.js'
import * as lock from './lock.js'
import * as unlock from './unlock.js'
export type Handler<Options = EmptyOptions> = DefaultHandler<Options, Context>
type Context = DefaultContext & ClientContext
interface ClientContext {
seam: Seam
}
const commands = [device, devices, lock, unlock]
const createAppContext: MiddlewareFunction = async (argv) => {
const apiKey = argv['api-key']
if (typeof apiKey !== 'string') throw new Error('Missing Seam API key')
const seam = Seam.fromApiKey(apiKey)
argv['seam'] = seam
}
const middleware = [...defaultMiddleware, createAppContext]
await landlubber<Context>(commands, { middleware })
.describe('api-key', 'Seam API key')
.string('api-key')
.default('api-key', env.SEAM_API_KEY, 'SEAM_API_KEY')
.demandOption('api-key')
.parse()