|
7 | 7 | * License v3.0 only", or the "Server Side Public License, v 1". |
8 | 8 | */ |
9 | 9 |
|
10 | | -import type { LogLevel } from '@kbn/tooling-log'; |
11 | | -import { pickLevelFromFlags, ToolingLog } from '@kbn/tooling-log'; |
12 | | -import type { ProcRunner } from '@kbn/dev-proc-runner'; |
13 | | -import { withProcRunner } from '@kbn/dev-proc-runner'; |
14 | 10 | import { createFlagError } from '@kbn/dev-cli-errors'; |
| 11 | +import { withProcRunner } from '@kbn/dev-proc-runner'; |
| 12 | +import { ToolingLog, pickLevelFromFlags } from '@kbn/tooling-log'; |
| 13 | +import { Cleanup } from '../cleanup'; |
| 14 | +import { DEFAULT_FLAG_ALIASES, getFlags } from '../flags/flags'; |
| 15 | +import { FlagsReader } from '../flags/flags_reader'; |
| 16 | +import { getHelp } from '../help'; |
| 17 | +import { Metrics } from '../metrics'; |
| 18 | +import type { RunFn, RunOptions } from './types'; |
| 19 | +import type { FlagOptions, Flags, FlagsOf } from '../flags/types'; |
15 | 20 |
|
16 | | -import type { Flags, FlagOptions } from './flags'; |
17 | | -import { getFlags, DEFAULT_FLAG_ALIASES } from './flags'; |
18 | | -import { FlagsReader } from './flags_reader'; |
19 | | -import { getHelp } from './help'; |
20 | | -import type { CleanupTask } from './cleanup'; |
21 | | -import { Cleanup } from './cleanup'; |
22 | | -import type { MetricsMeta } from './metrics'; |
23 | | -import { Metrics } from './metrics'; |
24 | | - |
25 | | -export interface RunContext { |
26 | | - log: ToolingLog; |
27 | | - flags: Flags; |
28 | | - procRunner: ProcRunner; |
29 | | - statsMeta: MetricsMeta; |
30 | | - addCleanupTask: (task: CleanupTask) => void; |
31 | | - flagsReader: FlagsReader; |
32 | | -} |
33 | | -export type RunFn<T = void> = (context: RunContext) => Promise<T> | void; |
34 | | - |
35 | | -export interface RunOptions { |
36 | | - usage?: string; |
37 | | - description?: string; |
38 | | - log?: { |
39 | | - defaultLevel?: LogLevel; |
40 | | - context?: string; |
41 | | - }; |
42 | | - flags?: FlagOptions; |
43 | | -} |
| 21 | +export async function run<T, TFlagOptions extends FlagOptions = FlagOptions>( |
| 22 | + fn: RunFn<T, FlagsOf<TFlagOptions>>, |
| 23 | + options?: RunOptions<TFlagOptions> |
| 24 | +): Promise<T | undefined>; |
44 | 25 |
|
45 | | -export async function run<T>(fn: RunFn<T>, options: RunOptions = {}): Promise<T | undefined> { |
| 26 | +export async function run<T>( |
| 27 | + fn: RunFn<T, Flags>, |
| 28 | + options: RunOptions = {} |
| 29 | +): Promise<T | undefined> { |
46 | 30 | const flags = getFlags(process.argv.slice(2), options.flags, options.log?.defaultLevel); |
47 | 31 | const log = new ToolingLog( |
48 | 32 | { |
|
0 commit comments