• Version 11.3.1
  • Published
  • 126 kB
  • 9 dependencies
  • MIT license


npm i @adonisjs/ace
yarn add @adonisjs/ace
pnpm add @adonisjs/ace


Commandline apps framework used by AdonisJs



variable args

const args: {
options?: Partial<Omit<CommandArg, 'type' | 'propertyName'>> | undefined
): <TKey extends string, TTarget extends { [K in TKey]?: string }>(
target: TTarget,
propertyName: TKey
) => void;
options?: Partial<Omit<CommandArg, 'type' | 'propertyName'>> | undefined
): <TKey_1 extends string, TTarget_1 extends { [K_1 in TKey_1]?: string[] }>(
target: TTarget_1,
propertyName: TKey_1
) => void;

    variable flags

    const flags: {
    string<T extends unknown>(
    options?: Partial<Omit<CommandFlag, 'type' | 'propertyName'>> | undefined
    ): <TKey extends string, TTarget extends { [K in TKey]: T }>(
    target: TTarget,
    propertyName: TKey
    ) => void;
    number<T_1 extends unknown>(
    options?: Partial<Omit<CommandFlag, 'type' | 'propertyName'>> | undefined
    ): <TKey_1 extends string, TTarget_1 extends { [K_1 in TKey_1]: T_1 }>(
    target: TTarget_1,
    propertyName: TKey_1
    ) => void;
    boolean<T_2 extends unknown>(
    options?: Partial<Omit<CommandFlag, 'type' | 'propertyName'>> | undefined
    ): <TKey_2 extends string, TTarget_2 extends { [K_2 in TKey_2]: T_2 }>(
    target: TTarget_2,
    propertyName: TKey_2
    ) => void;
    array<T_3 extends unknown>(
    options?: Partial<Omit<CommandFlag, 'type' | 'propertyName'>> | undefined
    ): <TKey_3 extends string, TTarget_3 extends { [K_3 in TKey_3]: T_3 }>(
    target: TTarget_3,
    propertyName: TKey_3
    ) => void;
    numArray<T_4 extends unknown>(
    options?: Partial<Omit<CommandFlag, 'type' | 'propertyName'>> | undefined
    ): <TKey_4 extends string, TTarget_4 extends { [K_4 in TKey_4]: T_4 }>(
    target: TTarget_4,
    propertyName: TKey_4
    ) => void;


      function handleError

      handleError: (
      error: any,
      callback?: (error: any) => void | Promise<void>
      ) => void;
      • Handles the command errors and prints them to the console.

      function listDirectoryFiles

      listDirectoryFiles: (
      scanDirectory: string,
      appRoot: string,
      filesToIgnore?: CommandsListFilterFn
      ) => string[];
      • Returns an array of Javascript files inside the current directory in relative to the application root.


      class BaseCommand

      abstract class BaseCommand implements CommandContract {}
      • Abstract base class other classes must extend


      constructor(application: ApplicationContract, kernel: KernelContract);
      • Accepting AdonisJs application instance and kernel instance

      property aliases

      static aliases: string[];
      • Command aliases

      property application

      application: ApplicationContract;

        property args

        static args: CommandArg[];
        • Command arguments

        property booted

        static booted: boolean;
        • Whether or not the command has been booted

        property colors

        colors: any;
        • Reference to the colors

        property commandName

        static commandName: string;
        • Command name. The command will be registered using this name only. Make sure their aren't any spaces inside the command name.

        property description

        static description: string;
        • The description of the command displayed on the help screen. A good command will always have some description.

        property error

        error?: any;
        • Error raised by the command

        property exitCode

        exitCode?: number;
        • Command exit code

        property exitHandler

        protected exitHandler?: () => void | Promise<void>;
        • Reference to the exit handler

        property flags

        static flags: CommandFlag[];
        • Command flags

        property generator

        generator: GeneratorContract;
        • Generator instance to generate entity files

        property isInteractive

        readonly isInteractive: boolean;
        • Terminal is interactive

        property isMain

        readonly isMain: boolean;
        • Is the current command the main command executed from the CLI

        property kernel

        kernel: KernelContract;

          property logger

          logger: any;
          • Returns the instance of logger to log messages

          property parsed

          parsed?: ParsedOptions;
          • Parsed options on the command. They only exist when the command is executed via kernel.

          property prompt

          prompt: any;
          • The prompt for the command

          property settings

          static settings: CommandSettings;
          • Any settings a command wants to have. Helpful for third party tools to read the settings in lifecycle hooks and make certain decisions

          property ui

          ui: {
          table: () => import('@poppinss/cliui/build/src/Table').Table;
          tasks: {
          (): import('@poppinss/cliui/build/src/Task/Manager').TaskManager;
          verbose(): import('@poppinss/cliui/build/src/Task/Manager').TaskManager;
          icons: {
          tick: string;
          cross: string;
          bullet: string;
          nodejs: string;
          pointer: string;
          info: string;
          warning: string;
          squareSmallFilled: string;
          logger: any;
          sticker: () => import('@poppinss/cliui/build/src/Instructions').Instructions;
          instructions: () => import('@poppinss/cliui/build/src/Instructions').Instructions;
          isInteractive: boolean;
          supportsColors: boolean;
          consoleRenderer: any;
          testingRenderer: any;
          • Reference to cli ui

          method $addArgument

          static $addArgument: (options: Partial<CommandArg>) => void;
          • Define an argument directly on the command without using the decorator

          method $addFlag

          static $addFlag: (options: Partial<CommandFlag>) => void;
          • Define a flag directly on the command without using the decorator

          method boot

          static boot: () => void;
          • Boots the command by defining required static properties

          method completed

          completed: (...args: any[]) => Promise<any>;

            method exec

            exec: () => Promise<any>;
            • Execute the command

            method exit

            exit: () => Promise<void>;
            • Trigger exit

            method handle

            handle: (...args: any[]) => Promise<any>;
            • Must be defined by the parent class

            method onExit

            onExit: (handler: () => void | Promise<void>) => this;
            • Register an onExit handler

            method prepare

            prepare: (...args: any[]) => Promise<any>;

              method run

              run: (...args: any[]) => Promise<any>;

                class Kernel

                class Kernel implements KernelContract {}
                • Ace kernel class is used to register, find and invoke commands by parsing process.argv.splice(2) value.


                constructor(application: ApplicationContract);

                  property aliases

                  aliases: { [alias: string]: string };

                    property application

                    application: ApplicationContract;

                      property commands

                      commands: { [name: string]: CommandConstructorContract };
                      • List of registered commands

                      property defaultCommand

                      defaultCommand: CommandConstructorContract;
                      • The default command that will be invoked when no command is defined

                      property error

                      error?: any;
                      • The error collected as part of the running commands or executing flags

                      property exitCode

                      exitCode?: number;
                      • The exit code for the process

                      property flags

                      flags: { [name: string]: CommandFlag & { handler: GlobalFlagHandler } };
                      • List of registered flags

                      property isInteractive

                      isInteractive: boolean;
                      • Find if CLI process is interactive. This flag can be toggled programmatically

                      property isMockingConsoleOutput

                      isMockingConsoleOutput: boolean;
                      • Find if console output is mocked

                      method after

                      after: {
                      (action: 'run', callback: RunHookCallback): this;
                      (action: 'find', callback: FindHookCallback): this;
                      • Register an after hook

                      method before

                      before: {
                      (action: 'run', callback: RunHookCallback): this;
                      (action: 'find', callback: FindHookCallback): this;
                      • Register a before hook

                      method exec

                      exec: (commandName: string, args: string[]) => Promise<CommandContract>;
                      • Execute a command as a sub-command. Do not call "handle" and always use this method to invoke command programatically

                      method exit

                      exit: (command: CommandContract, error?: any) => Promise<void>;
                      • Trigger kernel to exit the process. The call to this method is ignored when command is not same the entryCommand.

                        In other words, subcommands cannot trigger exit

                      method find

                      find: (argv: string[]) => Promise<CommandConstructorContract | null>;
                      • Finds the command from the command line argv array. If command for the given name doesn't exists, then it will return null.

                        Does executes the before and after hooks regardless of whether the command has been found or not

                      method flag

                      flag: (
                      name: string,
                      handler: GlobalFlagHandler,
                      options: Partial<Exclude<CommandFlag, 'name' | 'propertyName'>>
                      ) => this;
                      • Register a global flag. It can be defined in combination with any command.

                      method getSuggestions

                      getSuggestions: (name: string, distance?: number) => string[];
                      • Returns an array of command names suggestions for a given name.

                      method handle

                      handle: (argv: string[]) => Promise<void>;
                      • Makes instance of a given command by processing command line arguments and setting them on the command instance

                      method interactive

                      interactive: (state: boolean) => this;
                      • Toggle interactive state

                      method isMain

                      isMain: (command: CommandContract) => boolean;
                      • Find if a command is the main command. Main commands are executed directly from the terminal.

                      method mockConsoleOutput

                      mockConsoleOutput: () => this;
                      • Enforce mocking the console output. Command logs, tables, prompts will be mocked

                      method onExit

                      onExit: (callback: (kernel: this) => void | Promise<void>) => this;
                      • Register an exit handler

                      method preloadManifest

                      preloadManifest: () => Promise<void>;
                      • Preload the manifest file. Re-running this method twice will result in a noop

                      method printHelp

                      printHelp: (
                      command?: CommandConstructorContract,
                      commandsToAppend?: ManifestCommand[],
                      aliasesToAppend?: Record<string, string>
                      ) => void;
                      • Print the help screen for a given command or all commands/flags

                      method register

                      register: (commands: CommandConstructorContract[]) => this;
                      • Register an array of command constructors

                      method runDefaultCommand

                      runDefaultCommand: () => Promise<any>;
                      • Run the default command. The default command doesn't accept and args or flags.

                      method useManifest

                      useManifest: (manifestLoader: ManifestLoader) => this;
                      • Use manifest instance to lazy load commands

                      class ManifestGenerator

                      class ManifestGenerator {}
                      • Exposes the API to generate the ace manifest file. The manifest file contains the meta data of all the registered commands. This speeds up the boot cycle of ace


                      constructor(basePath: string, commands: string[]);

                        method generate

                        generate: () => Promise<void>;
                        • Generates and writes the ace manifest file to the base path

                        class ManifestLoader

                        class ManifestLoader implements ManifestLoaderContract {}
                        • The manifest loader exposes the API to load ace commands from one or more manifest files.


                        constructor(files: { basePath: string; manifestAbsPath: string }[]);

                          property booted

                          booted: boolean;

                            method boot

                            boot: () => Promise<void>;
                            • Boot manifest loader to read all manifest files from the disk

                            method getCommand

                            getCommand: (
                            commandName: string
                            ) => { basePath: string; command: ManifestCommand } | undefined;
                            • Returns manifest command node. One must load the command in order to use it

                            method getCommandBasePath

                            getCommandBasePath: (commandName: string) => string | undefined;
                            • Returns base path for a given command

                            method getCommands

                            getCommands: () => { commands: ManifestCommand[]; aliases: Aliases };
                            • Returns an array of manifest commands

                            method hasCommand

                            hasCommand: (commandName: string) => boolean;
                            • Find if a command exists or not

                            method loadCommand

                            loadCommand: (commandName: string) => Promise<CommandConstructorContract>;
                            • Load command from the disk. Make sure to use [[hasCommand]] before calling this method

                            Package Files (9)

                            Dependencies (9)

                            Dev Dependencies (23)

                            Peer Dependencies (1)


                            To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                            You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@adonisjs/ace.

                            • Markdown
                            • HTML
                              <a href="https://www.jsdocs.io/package/@adonisjs/ace"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>