Home Intro Source Mebo GitHub
import CliArgs from 'mebo/src/Readers/CliArgs.js'
public class | source

CliArgs

Extends:

Reader → CliArgs

command-line arguments reader.

This reader is used by the Cli handler. It supports most of the docopt specification. Also, if the reader finds an error it's capable of reporting it in user-friendly way. This is used to report -h/--help and missing arguments.

All serializable inputs are supported by this handler, they can be displayed either as argument or option element. This is done by setting the input property elementType (option is the default one).

You can define the description displayed in the help of each input by setting the input's property description. Also, the description for the action itself can be defined by setting the action's metadata description.

The option elements support short option by setting the input property shortOption.

In order to accommodate how vector values are represented in a command-line interface, this reader expects vector elements to be separated by the space character.

Any Bool input specified as an option element behaves in a special mode, since it's treated as a toogle option in command-line. Therefore if the Bool input is assigned with a true then the option gets the prefix no-.

When a value is found for the input, it gets loaded via Input.parseValue where each input implementation has its own way of parsing the serialized data, to find out about how a value is serialized for an specific input type you could simply set an arbitrary value to the input you are interested then query it back through Input.serializeValue. Also, Mebo provides a reference datasheet about the serialization forms for the inputs bundled with it, found at Reader.

See:

Constructor Summary

Public Constructor
public

constructor(action: Action, argv: Array<string>)

Creates an args reader

Method Summary

Public Methods
public

Returns a list of args used by the reader, by default it uses process.argv.

public

executableName(placeHolder: string): string

Returns the executable name based on the args

Protected Methods
protected

async _perform(inputList: Array<Input>): Promise<Object>

Implements the reader

protected

Computes the contents displayed as help

Inherited Summary

From class Reader
public

Returns the action associated with the reader.

public

Reads the autofill information and returns it through a plain object.

public

Reads the input values and returns it through a plain object.

public

option(path: string, defaultValue: *): *

Returns an option

public

setOption(path: string, value: *, merge: boolean)

Sets a value under the options

public

Returns a list of valid input names that should be used for the parsing.

protected

_perform(inputList: Array<Input>): Promise<Object>

This method should be re-implemented by derived classes to perform the handler parsing.

Public Constructors

public constructor(action: Action, argv: Array<string>) source

Creates an args reader

Override:

Reader#constructor

Params:

NameTypeAttributeDescription
action Action

action that should be used by the reader

argv Array<string>

list of arguments that should be used by the reader

Public Methods

public args(): Array<string> source

Returns a list of args used by the reader, by default it uses process.argv.

Return:

Array<string>

public executableName(placeHolder: string): string source

Returns the executable name based on the args

Params:

NameTypeAttributeDescription
placeHolder string

when placeHolder is enabled it returns an uuid string that can be used later to replace for the real executable name returned by default

Return:

string

Protected Methods

protected async _perform(inputList: Array<Input>): Promise<Object> source

Implements the reader

Override:

Reader#_perform

Params:

NameTypeAttributeDescription
inputList Array<Input>

Valid list of inputs that should be used for the parsing

Return:

Promise<Object>

protected _renderHelp(elements: Object): Promise<string> source

Computes the contents displayed as help

Params:

NameTypeAttributeDescription
elements Object

object generated by the method _helpElements

Return:

Promise<string>