Skip to content

Commit 65ce643

Browse files
authored
Add back examples (#57)
1 parent f78e356 commit 65ce643

7 files changed

Lines changed: 649 additions & 514 deletions

File tree

examples/devices.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { Builder, Command, Describe } from 'landlubber'
2+
3+
import type { Handler } from './index.js'
4+
5+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
6+
interface Options {}
7+
8+
export const command: Command = 'devices'
9+
10+
export const describe: Describe = 'List devices'
11+
12+
export const builder: Builder = {}
13+
14+
export const handler: Handler<Options> = async ({ seam, logger }) => {
15+
const devices = await seam.devices.list()
16+
logger.info({ devices }, 'devices')
17+
}

examples/index.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env tsx
2+
3+
import { env } from 'node:process'
4+
5+
import landlubber, {
6+
type DefaultContext,
7+
defaultMiddleware,
8+
type EmptyOptions,
9+
type Handler as DefaultHandler,
10+
type MiddlewareFunction,
11+
} from 'landlubber'
12+
13+
import { Seam } from 'seam'
14+
15+
import * as devices from './devices.js'
16+
17+
export type Handler<Options = EmptyOptions> = DefaultHandler<Options, Context>
18+
19+
type Context = DefaultContext & ClientContext
20+
21+
interface ClientContext {
22+
seam: Seam
23+
}
24+
25+
const commands = [devices]
26+
27+
const createAppContext: MiddlewareFunction = async (argv) => {
28+
const apiKey = argv['api-key']
29+
if (typeof apiKey !== 'string') throw new Error('Missing Seam API key')
30+
const seam = Seam.fromApiKey(apiKey)
31+
argv['seam'] = seam
32+
}
33+
34+
const middleware = [...defaultMiddleware, createAppContext]
35+
36+
await landlubber<Context>(commands, { middleware })
37+
.describe('api-key', 'Seam API key')
38+
.string('api-key')
39+
.default('api-key', env.SEAM_API_KEY, 'SEAM_API_KEY')
40+
.demandOption('api-key')
41+
.parse()

0 commit comments

Comments
 (0)