Documentation
    Preparing search index...

    The list command is used to view a list of commands

    // Usage from CLI: node ace list
    // Or with namespace filter: node ace list migrate
    // Or as JSON: node ace list --json
    const listCommand = new ListCommand(kernel, parsed, ui, prompt)
    await listCommand.run()

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    booted: boolean = false

    Whether the command class has been booted

    Configuration options accepted by the command

    aliases: string[]

    A collection of aliases for the command

    args: Argument[]

    Registered arguments

    flags: Flag[]

    Registered flags

    exitCode?: number

    The exit code for the command

    error?: any

    The error raised at the time of executing the command. The value is undefined if no error is raised.

    result?: any

    The result property stores the return value of the "run" method (unless command sets it explicitly)

    ui: {}

    UI primitives for output

    prompt: Prompt

    Prompt utilities for user interaction

    commandName: string = 'list'

    Command metadata

    description: string = 'View list of available commands'

    The command description

    help: string[] = ...

    The help text for the command. Help text can be a multiline string explaining the usage of command

    namespaces?: string[]

    Optional namespaces to filter the command list

    json?: boolean

    Flag to output the command list as JSON

    Accessors

    • get logger(): Logger

      Logger to log messages

      Returns Logger

      this.logger.info('Command executed successfully')
      this.logger.error('Something went wrong')
    • get colors(): Colors

      Add colors to console messages

      Returns Colors

      this.logger.info(this.colors.green('Success!'))
      this.logger.error(this.colors.red('Error!'))
    • get isMain(): boolean

      Is the current command the main command executed from the CLI

      Returns boolean

      if (this.isMain) {
      this.logger.info('This is the main command')
      }
    • get commandName(): string

      Reference to the command name

      Returns string

    Methods

    • Define static properties on the class. During inheritance, certain properties must inherit from the parent.

      Returns void

      MyCommand.boot()
      
    • Specify the argument the command accepts. The arguments via the CLI will be accepted in the same order as they are defined.

      Mostly, you will be using the @args decorator to define the arguments.

      Parameters

      • name: string

        The name of the argument

      • options: Partial<Argument> & { type: "string" | "spread" }

        Configuration options for the argument

      Returns void

      Command.defineArgument('entity', { type: 'string' })
      Command.defineArgument('files', { type: 'spread', required: false })
    • Specify a flag the command accepts.

      Mostly, you will be using the @flags decorator to define a flag.

      Parameters

      • name: string

        The name of the flag

      • options: Partial<Flag> & { type: "string" | "number" | "boolean" | "array" }

        Configuration options for the flag

      Returns void

      Command.defineFlag('connection', { type: 'string', required: true })
      Command.defineFlag('force', { type: 'boolean' })
      Command.defineFlag('tags', { type: 'array' })
    • Validate the yargs parsed output against the command.

      Parameters

      Returns void

      const parsed = { args: ['value'], flags: { force: true }, unknownFlags: [] }
      MyCommand.validate(parsed)
    • Hydrate command by setting class properties from the parsed output

      Returns void

      command.hydrate()
      console.log(command.name) // Argument value
      console.log(command.force) // Flag value
    • Executes the command by running the command's run method.

      Returns Promise<any>

      const result = await command.exec()
      console.log('Exit code:', command.exitCode)
    • JSON representation of the command

      Returns {
          commandName: string;
          options: CommandOptions;
          args: any[];
          flags: { [argName: string]: any };
          error: any;
          result: any;
          exitCode: undefined | number;
      }

      const json = command.toJSON()
      console.log(json.commandName, json.exitCode)
    • Assert the command exits with a given exit code

      Parameters

      • code: number

        The expected exit code

      Returns void

      command.assertExitCode(0) // Assert successful execution
      command.assertExitCode(1) // Assert failure
    • Assert the command does not exit with a given exit code

      Parameters

      • code: number

        The exit code that should not be used

      Returns void

      command.assertNotExitCode(1) // Assert no failure
      
    • Assert command logs the expected message

      Parameters

      • message: string

        The expected log message

      • Optionalstream: "stdout" | "stderr"

        Optional stream to check ('stdout' or 'stderr')

      Returns void

      command.assertLog('Command executed successfully')
      command.assertLog('Error occurred', 'stderr')
    • Assert command logs a message matching the given regex

      Parameters

      • matchingRegex: RegExp

        The regex pattern to match against log messages

      • Optionalstream: "stdout" | "stderr"

        Optional stream to check ('stdout' or 'stderr')

      Returns void

      command.assertLogMatches(/^Command.*completed$/)
      command.assertLogMatches(/error/i, 'stderr')
    • Assert the command prints a table with the expected rows to stdout

      Parameters

      • rows: string[][]

        The expected table rows as arrays of strings

      Returns void

      command.assertTableRows([
      ['Name', 'Age'],
      ['John', '25'],
      ['Jane', '30']
      ])
    • Executes the list command to display available commands

      Returns Promise<void>

      await listCommand.run()