# 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:

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

node maker make-command SendEmails

Let's take a look at an example command:

"use strict";
const Command = require("maker-console");

class SendMail extends Command {
  constructor() {
    super();
    /**
     * The name and signature of the console command.
     * @var string
     */
    this.signature = "sendMail";

    /**
     * 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"}]
     * @var array
     */
    this.arguments = [];

    /**
     * The console command description.
     * @var string
     */
    this.description = "Send email to users";

    super.checkCommandName(this.signature);
  }

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

module.exports = SendMail;

# 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";
const Command = require("maker-console");

class SendMail extends Command {
  constructor() {
    super();
    /**
     * The name and signature of the console command.
     * @var string
     */
    this.signature = "sendMail";

    /**
     * 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"}]
     * @var array
     */
    this.arguments = [{name:”emailAddress”,mode:REQUIRED}];

    /**
     * The console command description.
     * @var string
     */
    this.description = "Send email to users";

    super.checkCommandName(this.signature);
  }

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

module.exports = SendMail;

# 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/SendMail_command.js"];
  }
}

module.exports = Kernel;