The Grind CLI is triggered via bin/cli. Running bin/cli --help will show you a list of available commands to run.

All commands support passing a --help command to tell you more about the command, including options and arguments available.

$ bin/cli make:model --help
  Usage: make:model [options],<className?>
  Create a model class
    -h, --help            output usage information
    -t, --table [string]  Name of the table to create the model for

The fastest way to create a new command is by using the command generator via bin/cli make:command.

You can invoke make:command with a few different arguments:

  • bin/cli make:command MakeThingCommand will create app/Commands/MakeThingCommand.js, but will not infer a command name.
  • bin/cli make:command --comandName=make:thing will also create app/Commands/MakeThingCommand.js and will set the command name for you.
  • You can also pass both a class name and a command name at the same time — though this isn’t advised.

All command names should be formatted as namespace:name, in the above example make is the namespace and thing is the name.

Class names should follow the command name with a Command suffix, so make:thing becomes MakeThingCommand.

Once you’ve triggered make:command, a class is generated for you that looks like this:

import { Command } from 'grind-cli'
export class MakeThingCommand extends Command {
  // Name of the command 
  name = 'make:thing'
  // Description of the command to show in help 
  description = 'Command description'
  // Arguments available for this command 
  arguments = [ 'requiredArgument', 'optionalArgument?' ]
  // Options for this command 
  options = {
    'some-option': 'Description of this option'
  run() {
    // Build something great! 

The name of the command is what you invoke via bin/cli, so for MakeThingCommand we would invoke it by calling bin/cli make:thing

The description is what shows up in bin/cli --help for your command. You should provide a short, concise description of what your command does.

Arguments are data passed into your command, in the order they’re declared. You can have an optional argument by ending the name with a question mark: optionalArgument?.

  • bin/cli make:thing name would give requiredArgument a value of name and optionalArgument would be null.
  • bin/cli make:thing name otherName would still give requiredArgument a value of name, however optionaArgument would now have a value of otherName

Options are flags passed to your command via two leading dashes, if options expect a value, the value is passed by using an equals sign:

  • bin/cli make:thing --some-option gives some-option a value of true
  • bin/cli make:thing --some-option=grind gives some-option a value of grind

Options can be passed in before or after arguments and will not affect the order in which arguments are processed in.

Options are declared by setting options to an object with the key being the name of the option, and the value it’s description:

options = {
  'some-option': 'Description of this option'

You can also require a value for your option (instead of accepting a boolean flag) by passing the value an array with the first element being the description, and the second being the type of value (currently only string is accepted):

options = {
  'some-option': [ 'Description of this option', 'string' ]

The run function is what is called when your command is invoked. CLI supports run returning a promise for asynchronous support.

You can also add a ready function to your command to perform startup tasks to be run when your command is invoked, but before run is called. CLI supports ready returning a promise for asynchronous support.

For instance, you may want to ready to load data to be used during the execution of the command:

import fs from 'fs-promise'
export class MakeThingCommand extends Command {
  ready() {
    return fs.readFile('countries.json'))
    .then(data => {
      this.countries = JSON.parse(data)

Now when run is called, it will already have this.countries populated.

You can retrieve arguments and options via the argument and option functions.

const value = this.argument(name, fallback)
  • name — The name of the argument to get the value of
  • fallback — Optional parameter to provide a default value for optional arguments. Passing a value here for a required argument will have no effect, since the your command won’t execute unless all required arguments are satisfied.

const value = this.option(name, fallback)
  • name — The name of the option to get the value of
  • fallback — Optional parameter to provide a default value for an option not provided

You prompt the user for input via the ask and confirm functions.

this.ask('What is your name?').then(answer => this.comment(`Hello ${answer}`))

The ask function takes a single question parameter, which is then outputted to the user, and returns a promise. The promise will resolve with the user’s answer to the question.

this.confirm('Are you sure you want to proceed?', false).then(answer => /* … */)

The confirm function is a helpful wrapper around ask for asking binary questions. The first parameter is question, which is outputted to the user. The second parameter is defaultAnswer, the defaultAnswer answer is used when the user provides no response and just hits enter.

confirm will accept accept the following user answers as true (case-insensitive):

  • true
  • t
  • 1
  • yes
  • y

All other input from the user will be evaluated as false.

The Command class has the following methods available for writing output to the terminal:

info(...message) // Outputs default text color 
comment(...message) // Outputs as blue text 
warn(...message) // Outputs as yellow text 
error(...message) // Outputs as white text with a red background 
success(...message) // Output as green text 

These methods simply call the same method on app.cli.output, which itself redirects to the global Log class. For more information logging and providing your own logger, see the Logging documentation.

Grind’s providers ship with a bunch of default commands to help make development easier.

Assets includes the assets:publish and assets:unpublish commands to help precompile your assets during deployment. See the Assets documentation for more information.

As noted above, the CLI includes a built in make:command command to generate commands for you.

The database provider includes a number of commands for migrating and seeding the database:

  • make:migration – Creates a migration file
  • make:seed – Creates a database seed file
  • migrate:current-version – Displays the current migration version
  • migrate:latest — Runs all outstanding migrations
  • migrate:rollback — Reverts the last set of migrations performed
  • db:seed — Runs all seed files to populate your database

See the Migrations & Seeds documentation for more information.

ORM has a single make:model command that generates model classes for you. See the ORM documentation for more information.