Bug toolGitHub
Edit on GitHub

Main parameter usage

Description

Main is what is left once the option and the commands have been extracted. Like with options, the main property is defined at the application level or for each command.

Definition

The main property is declared as an object with the following properties:

  • name (string)
    The name of the main property.
  • required (boolean || function)
    Whether or not the value must always be present.
  • description (string)
    The description of the main argument.

As an alternative, a "string" can also be provided which will be converted to an object with the name property set to the original string value. Thus, the following declarations are equivalent:

shell({
  main: 'input'  
})
// is equivalent to
shell({
  main: {
    name: 'input' 
  } 
})

The extracted value is an array.

If no main arguments is defined in the CLI commands, then the array is empty.

require('should')
require('shell')({
  main: 'input' 
})
.parse([])
.should.eql({
  input: []
})

Using required as a function

When required is a function, the first argument is an object with the following properties:

  • config
    The configuration associated with the command or the full configuration is no command is used.
  • command The current command name, use config.command to acess the full command as an array.

Examples

Application level definition

require("shell")({
  main: "leftover"
})

The above is the equivalent of declaring options as an array like:

require("shell")({
  main: {
    name: "leftover"
}})

Usage of the "main" parameter is now: myapp [leftover].

Command level definition

require("shell")({
  commands: [{
    name: 'server',
    commands: [{
      name: 'start',
      main: 'leftover'
}]}]})

Usage of the "main" parameter is now: myapp server start [leftover].

About

Node.js Parameters is the tool for building CLI applications with Node.js. It is developed and supported by Adaltas.