---
source: lib/src/sdk/typescript/types.rs
expression: "get_file(&output, \"client.ts\")"
---
// @generated by usage-cli from test.usage.kdl. Do not edit manually.
import { CliRunner, CliResult } from "./runtime";
import { BuildArgs, BuildFlags, DeployArgs, DeployFlags, EnvChoice, GlobalFlags, MytoolArgs, MytoolFlags, TargetChoice } from "./types";

export class Mytool {
  private runner: CliRunner;
  /** Build the project. @deprecated Use 'compile' instead */
  readonly build: Build;
  /** Deploy the project */
  readonly deploy: Deploy;
  /** Alias for `build` */
  get b(): Build { return this.build; }

  constructor(binPath?: string) {
    this.runner = new CliRunner(binPath ?? "mytool");
    this.build = new Build(this.runner);
    this.deploy = new Deploy(this.runner);
  }
  /** [FLAGS] <input> <extra>… <SUBCOMMAND> */
  async exec(args: MytoolArgs, flags?: MytoolFlags): Promise<CliResult> {
    const cmdArgs: string[] = [];
    if (args.input !== undefined) { cmdArgs.push(String(args.input)); }
    if (args.extra !== undefined) { cmdArgs.push(...args.extra); }
    const flagArgs = this.buildFlagArgs(flags);
    return this.runner.run([...cmdArgs, ...flagArgs]);
  }

  private buildFlagArgs(flags?: MytoolFlags): string[] {
    const result: string[] = [];
    if (!flags) return result;
    if (flags.verbose !== undefined && flags.verbose > 0) { for (let i = 0; i < flags.verbose; i++) { result.push("--verbose"); } }
    if (flags.config !== undefined) { result.push("--config", String(flags.config)); }
    if (flags.dryRun) { result.push("--dry-run"); }
    else if (flags.dryRun === false) { result.push("--no-dry-run"); }
    return result;
  }
}

/**
 * Build the project
 * @deprecated Use 'compile' instead
 * Aliases: b
 */
export class Build {
  private runner: CliRunner;

  constructor(runner: CliRunner) {
    this.runner = runner;
  }
  /**
   * build [-j --jobs… <n>] [--release] <target> <-- output>
   * @example Build in release mode
   * ```bash
   * mytool build --release target
   * ```
   */
  async exec(args: BuildArgs, flags?: BuildFlags): Promise<CliResult> {
    const cmdArgs: string[] = ["build"];
    if (args.target !== undefined) { cmdArgs.push(String(args.target)); }
    cmdArgs.push("--");
    if (args.output !== undefined) { cmdArgs.push(String(args.output)); }
    const flagArgs = this.buildFlagArgs(flags);
    return this.runner.run([...cmdArgs, ...flagArgs]);
  }

  private buildFlagArgs(flags?: BuildFlags): string[] {
    const result: string[] = [];
    if (!flags) return result;
    if (flags.verbose !== undefined && flags.verbose > 0) { for (let i = 0; i < flags.verbose; i++) { result.push("--verbose"); } }
    if (flags.config !== undefined) { result.push("--config", String(flags.config)); }
    if (flags.jobs !== undefined) { for (const v of flags.jobs) { result.push("--jobs", String(v)); } }
    if (flags.release) { result.push("--release"); }
    return result;
  }
}

/** Deploy the project */
export class Deploy {
  private runner: CliRunner;

  constructor(runner: CliRunner) {
    this.runner = runner;
  }
  /** deploy [-f --force] [--confirm] <env> <tags>… */
  async exec(args: DeployArgs, flags?: DeployFlags): Promise<CliResult> {
    const cmdArgs: string[] = ["deploy"];
    if (args.env !== undefined) { cmdArgs.push(String(args.env)); }
    if (args.tags !== undefined) { cmdArgs.push(...args.tags); }
    const flagArgs = this.buildFlagArgs(flags);
    return this.runner.run([...cmdArgs, ...flagArgs]);
  }

  private buildFlagArgs(flags?: DeployFlags): string[] {
    const result: string[] = [];
    if (!flags) return result;
    if (flags.verbose !== undefined && flags.verbose > 0) { for (let i = 0; i < flags.verbose; i++) { result.push("--verbose"); } }
    if (flags.config !== undefined) { result.push("--config", String(flags.config)); }
    if (flags.force) { result.push("--force"); }
    if (flags.confirm) { result.push("--confirm"); }
    return result;
  }
}
