# Maker Console

Maker is the command line interface for ExpressWebJs. Maker exists at the root of your application as the maker script and provides a number of helpful commands that can assist you while you build your application. To view a list of all available Maker commands, you may use the help command:

 ts-node maker -h

# Writing Commands

To create a new command, you may use the make-command .This command will create a new command class in the App/Console/Commands directory. Don't worry if this directory does not exist in your application, it will be created the first time you run the make-command

  ts-node maker make-command SendEmails

Let's take a look at an example command:

"use strict";
import Command from "maker-console-ts";

class SendEmails extends Command {
  signature: string;
  arguments: object[];
  description: string;
  constructor() {
    super();
    //The name or signature of the console command.
    this.signature = "";

    /**
     * The name and mode of the console command argument.
     * name is the name of the argument while mode can be REQUIRED or OPTIONAL
     * Example [{name: "Debug", mode: "REQUIRED"},{name: "Task", mode: "REQUIRED"}]
     */
    this.arguments = [];

    /**
     * The console command description.
     * @var string
     */
    this.description = "";

    super.checkCommandName(this.signature);
  }

  /**
   * Execute the console command.
   *
   * @return mixed
   */
  fire() {
    //
  }
}

export default SendEmails;

# Command Structure

After Generating your maker command, you should define appropriate values for the signature,arguments and description properties of the class. These properties will be used when adding your command to the maker command.

The arguments property allows you to define your commands arguments which can be REQUIRED or OPTIONAL.

To define an argument of emailAddress in the SendEmails command, we can do so:

this.arguments = [{name:”emailAddress”,mode:REQUIRED}].

You can add multiple arguments.

# fire method

The fire method will be called when your command is executed. You may place your command logic in this method.

# Retrieving Input

While your command is executing, you will likely need to access the values for the arguments and options accepted by your command. To do so, you may add the argument name as a parameter to the fire method. If the argument does not exist, undefined will be returned.

"use strict";
import Command from "maker-console-ts";

class SendEmails extends Command {
  signature: string;
  arguments: object[];
  description: string;
  constructor() {
    super();
    //The name or signature of the console command.
    this.signature = "";

    /**
     * The name and mode of the console command argument.
     * name is the name of the argument while mode can be REQUIRED or OPTIONAL
     * Example [{name: "Debug", mode: "REQUIRED"},{name: "Task", mode: "REQUIRED"}]
     */
    this.arguments = [{name:”emailAddress”,mode:REQUIRED}];

    /**
     * The console command description.
     * @var string
     */
    this.description = "";

    super.checkCommandName(this.signature);
  }

  /**
   * Execute the console command.
   *
   * @return mixed
   */
  fire() {
    console.log("sending email to users");
  }
}

export default SendEmails;

# Registering Your Command

All of your console commands are registered within your application's App\Console\Kernel class, which is your application's console kernel. You may register commands by adding the command namespace (path) to the commands method of your App\Console\Kernel class. When Maker boots, all the commands listed in commands method will be resolved and registered with Maker:

"use strict";

class Kernel {
  /**
   * The Maker commands provided by your application.
   * @var array
   */
  static commands() {
    return ["App/Console/Commands/SendEmails_command.ts"];
  }
}

export default Kernel;