---
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 { Arg2Choice, InstallArgs, InstallFlags, MycliArgs, MycliFlags, ShellChoice } from "./types";

export class Mycli {
  private runner: CliRunner;
  readonly plugin: Plugin;

  constructor(binPath?: string) {
    this.runner = new CliRunner(binPath ?? "mycli");
    this.plugin = new Plugin(this.runner);
  }
  /** [FLAGS] <ARGS>… <SUBCOMMAND> */
  async exec(args: MycliArgs, flags?: MycliFlags): Promise<CliResult> {
    const cmdArgs: string[] = [];
    if (args.arg1 !== undefined) { cmdArgs.push(String(args.arg1)); }
    if (args.arg2 !== undefined) { cmdArgs.push(String(args.arg2)); }
    if (args.arg3 !== undefined) { cmdArgs.push(String(args.arg3)); }
    if (args.argrest !== undefined) { cmdArgs.push(...args.argrest); }
    if (args.withDefault !== undefined) { cmdArgs.push(String(args.withDefault)); }
    const flagArgs = this.buildFlagArgs(flags);
    return this.runner.run([...cmdArgs, ...flagArgs]);
  }

  private buildFlagArgs(flags?: MycliFlags): string[] {
    const result: string[] = [];
    if (!flags) return result;
    if (flags.flag1) { result.push("--flag1"); }
    if (flags.flag2) { result.push("--flag2"); }
    if (flags.flag3) { result.push("--flag3"); }
    else if (flags.flag3 === false) { result.push("--no-flag3"); }
    if (flags.withDefault) { result.push("--with-default"); }
    if (flags.shell !== undefined) { result.push("--shell", String(flags.shell)); }
    return result;
  }
}

export class Plugin {
  private runner: CliRunner;
  readonly install: Install;

  constructor(runner: CliRunner) {
    this.runner = runner;
    this.install = new Install(this.runner);
  }
  /** plugin <SUBCOMMAND> */
  async exec(): Promise<CliResult> {
    return this.runner.run(["plugin"]);
  }
}

/** install a plugin */
export class Install {
  private runner: CliRunner;

  constructor(runner: CliRunner) {
    this.runner = runner;
  }
  /** plugin install [FLAGS] <plugin> <version> */
  async exec(args: InstallArgs, flags?: InstallFlags): Promise<CliResult> {
    const cmdArgs: string[] = ["plugin", "install"];
    if (args.plugin !== undefined) { cmdArgs.push(String(args.plugin)); }
    if (args.version !== undefined) { cmdArgs.push(String(args.version)); }
    const flagArgs = this.buildFlagArgs(flags);
    return this.runner.run([...cmdArgs, ...flagArgs]);
  }

  private buildFlagArgs(flags?: InstallFlags): string[] {
    const result: string[] = [];
    if (!flags) return result;
    if (flags.global) { result.push("--global"); }
    if (flags.dir !== undefined) { result.push("--dir", String(flags.dir)); }
    if (flags.force) { result.push("--force"); }
    else if (flags.force === false) { result.push("--no-force"); }
    return result;
  }
}
