---
source: lib/src/sdk/typescript/types.rs
expression: client
---
// @generated by usage-cli from test.usage.kdl. Do not edit manually.
import { CliRunner, CliResult } from "./runtime";
import { RunArgs, RunnerArgs, RunnerFlags } from "./types";

export class Runner {
  private runner: CliRunner;
  /** Run a task */
  readonly run: Run;

  constructor(binPath?: string) {
    this.runner = new CliRunner(binPath ?? "runner");
    this.run = new Run(this.runner);
  }
  /** [--verbose…] <input> <extra>… <SUBCOMMAND> */
  async exec(args: RunnerArgs, flags?: RunnerFlags): Promise<CliResult> {
    const cmdArgs: string[] = [];
    if (args.input !== undefined) { cmdArgs.push(String(args.input)); }
    if (args.extra !== undefined) { cmdArgs.push(...args.extra); }
    // double_dash=automatic: "--" is implied after the first positional arg
    const flagArgs = this.buildFlagArgs(flags);
    return this.runner.run([...cmdArgs, ...flagArgs]);
  }

  private buildFlagArgs(flags?: RunnerFlags): string[] {
    const result: string[] = [];
    if (!flags) return result;
    if (flags.verbose !== undefined) { for (const v of flags.verbose) { if (v) result.push("--verbose"); } }
    return result;
  }
}

/** Run a task */
export class Run {
  private runner: CliRunner;

  constructor(runner: CliRunner) {
    this.runner = runner;
  }
  /**
   * run <task>
   * @example Basic run
   * ```
   * runner run hello
   * ```
   */
  async exec(args: RunArgs): Promise<CliResult> {
    const cmdArgs: string[] = ["run"];
    if (args.task !== undefined) { cmdArgs.push(String(args.task)); }
    // double_dash=automatic: "--" is implied after the first positional arg
    return this.runner.run(cmdArgs);
  }
}
