|
1 | 1 | #!/usr/bin/env tsx |
2 | 2 |
|
3 | | -import landlubber from 'landlubber' |
| 3 | +import { env } from 'node:process' |
4 | 4 |
|
5 | | -import * as todo from './todo.js' |
| 5 | +import landlubber, { |
| 6 | + type DefaultContext, |
| 7 | + defaultMiddleware, |
| 8 | + type EmptyOptions, |
| 9 | + type Handler as DefaultHandler, |
| 10 | + type MiddlewareFunction, |
| 11 | +} from 'landlubber' |
6 | 12 |
|
7 | | -const commands = [todo] |
| 13 | +import { SeamHttp } from '@seamapi/http/connect' |
8 | 14 |
|
9 | | -await landlubber(commands).parse() |
| 15 | +import * as workspace from './workspace.js' |
| 16 | + |
| 17 | +export type Handler<Options = EmptyOptions> = DefaultHandler<Options, Context> |
| 18 | + |
| 19 | +type Context = DefaultContext & ClientContext |
| 20 | + |
| 21 | +interface ClientContext { |
| 22 | + client: SeamHttp |
| 23 | +} |
| 24 | + |
| 25 | +const commands = [workspace] |
| 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 client = SeamHttp.fromApiKey(apiKey) |
| 31 | + argv['client'] = client |
| 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