Usage Generators

Mustard provides built-in usage generators for commands, which will collect all the options info and command registry info to generate usage information for commands.

import { MustardFactory } from "../../../Exports/index";
import {
  RootCommand,
  Option,
  VariadicOption,
  App,
  Input,
  Options,
  Command,
} from "../../../Exports/Decorators";
import { CommandStruct } from "../../../Exports/ComanndLine";

@Command("update", "u", "update command")
class UpdateCommandHandle implements CommandStruct {
  @Option("msg", "m")
  public msg = "default value of msg";

  @Option()
  public notice = "default value of notice";

  @VariadicOption({ alias: "p" })
  public projects: string[] = [];

  @Input("description of inputs")
  public these_are_inputs: string;

  @Options()
  public options: unknown;

  public run(): void {}
}

@App({
  name: "mm",
  commands: [UpdateCommandHandle],
})
class Project {}

MustardFactory.init(Project).start();

Generated usage information:

    Usage:

      $ mm [command] [--options]

    Command:
      update, u, update command

    Options:
      --msg, -m, default: "default value of msg"
      --notice, default: "default value of notice"
      --projects, -p, default: []

Nested commands:

import { MustardFactory } from "../../../Exports/index";
import {
  RootCommand,
  Option,
  VariadicOption,
  App,
  Input,
  Options,
  Command,
} from "../../../Exports/Decorators";
import { CommandStruct } from "../../../Exports/ComanndLine";

@Command("update", "u", "update command")
class UpdateCommandHandle implements CommandStruct {
  @Option("msg", "m")
  public msg = "default value of msg";

  @Option()
  public notice = "default value of notice";

  @VariadicOption({ alias: "p" })
  public projects: string[] = [];

  @Input("description of inputs")
  public these_are_inputs: string;

  @Options()
  public options: unknown;

  public run(): void {}
}

@Command("sync", "s", "sync command")
class SyncCommandHandle implements CommandStruct {
  @Option("msg", "m")
  public msg = "default value of msg";

  @Option()
  public notice = "default value of notice";

  @VariadicOption({ alias: "p" })
  public projects: string[] = [];

  @Input("description of inputs")
  public these_are_inputs: string;

  @Options()
  public options: unknown;

  public run(): void {}
}

@App({
  name: "mm",
  commands: [UpdateCommandHandle, SyncCommandHandle],
})
class Project {}

MustardFactory.init(Project).start();

Generated usage information:

  Usage:

      $ mm [command] [--options]

    Command:
      update, u, update command

    Options:
      --msg, -m, default: "default value of msg"
      --notice, default: "default value of notice"
      --projects, -p, default: []

    Command:
      sync, s, sync command

    Options:
      --msg, -m, default: "default value of msg"
      --notice, default: "default value of notice"
      --projects, -p, default: []