@absolunet/ioc2.1.0

View on GitHub

GeneratorCommand

This abstract class allows to create a command that generates a file. It is normally used to create a command, a controller, a migration, any kind of file. It relies on existing stub that will be formatted with a given grammar.

Extends

Members

(static) abstract

Source:

type :string

Source:
Get the class type that is being made.

(abstract) files :object.<string, string>

Source:
Files accessor. It should offers a dictionary associating the type of file to the specific stub.

(abstract) destination :string

Source:
Destination accessor. It should indicates the root folder in which the file should be written. If it returns /foo/bar and the file to be created is baz/Qux, the the final destination will be /foo/bar/baz/Qux.js.

fileName :string

Source:
Filename accessor. It build the file name based on user input.

patterns :object.<string, string>

Source:
Replacement patterns accessor.
Example
const { patterns } = generatorCommand; // { REPLACE: "bar" }
const stub = 'Foo %REPLACE% baz';
generatorCommand.replace(stub, patterns); // "Foo bar baz"

policies :Array.<string>

Source:
Overrides:
Specify policies for the command.

(abstract) name :string

Source:
Inherited From:
Command name accessor.

description :string

Source:
Overrides:
Command description accessor.

forward :string|null

Source:
Inherited From:
Command to forward the current command.

signature :string

Source:
Inherited From:
Yargs signature accessor.

parameters :Array.<Array.<(string|boolean|null)>>

Source:
Overrides:
Raw parameters accessor. A parameter is normally located after the command name in a CLI input: "node ioc foo:bar parameter --option=value --flag".
Example
[
		['name',   true,  null,   'The required name.'],
		['prefix', false, '',     'The optional prefix.'],
		['suffix', false, '-foo', 'The optional suffix, which is set to "-foo" by default.']
]

options :Array.<Array.<(string|boolean|null)>>

Source:
Overrides:
Raw options accessor. An option is normally located after the command parameters in a CLI input: "node ioc foo:bar parameter --option=value --flag".
Example
[
		['foo', null,  'The foo option'],
		['bar', 'baz', 'The bar option, which is set to "baz" by default.']
]

flags :Array.<Array.<string>>

Source:
Inherited From:
Raw flags accessor. A flag is normally located after the command options in a CLI input: "node ioc foo:bar parameter --option=value --flag".
Example
[
		['foo', 'Some flag'],
		['bar', 'Some other flag']
]

args :object

Source:
Inherited From:
Current arguments accessor.

verbose :number

Source:
Inherited From:
Get verbose level, from 0 to 3.
Example
"node ioc some:command"; // 0
"node ioc some:command --verbose"; // 1
"node ioc some:command -v"; // 1
"node ioc some:command -vv"; // 2
"node ioc some:command -vvv"; // 3

yargs :yargs

Source:
Overrides:
Yargs instance accessor.

yargsModel :Object

Source:
Inherited From:
Yargs command model accessor.

argumentModels :Object

Source:
Inherited From:
Argument models mapping accessor.

outputInterceptor :function

Source:
Inherited From:
Output interceptor function.

interceptor :console.services.Interceptor

Source:
Inherited From:
The terminal interceptor.

Methods

generate(type)

Source:
See:
  • GeneratorCommand#files
Generate a file of a specific type from stubs.
Parameters:
Name Type Description
type string The file type to generate.
Returns:
The async writing process.
Type
Promise.<boolean>

load(type)

Source:
See:
  • GeneratorCommand#files
Load a given stub by name.
Parameters:
Name Type Description
type string The file type to load.
Returns:
The file content.
Type
string

replace(content, patterns)

Source:
Mass replace file parts based on patterns.
Parameters:
Name Type Description
content string The content to format.
patterns object.<string, string> The patterns to replace.
Returns:
The formatted content.
Type
string

(async) write(content)

Source:
Overrides:
Write the given file to the configured destination folder.
Parameters:
Name Type Description
content string The content to write.
Returns:
The async promise.
Type
Promise.<boolean>

getDestination()

Source:
See:
  • GeneratorCommand#destination
  • GeneratorCommand#fileName
Get destination folder.
Returns:
The final file destination.
Type
string

preprocess(input)

Source:
Inherited From:
Preprocess args before handling the command.
Parameters:
Name Type Description
input object.<string, string> The user input.
Returns:
A preprocessed input.
Type
Promise.<object.<string, string>> | object.<string, string>

(abstract) handle()

Source:
Inherited From:
Handle the command. If it returns a value, it will be send to the postprocess method.
Returns:
The async process promise.
Type
void | Promise

(async) postprocess(outputopt)

Source:
Inherited From:
Postprocess the handled data.
Parameters:
Name Type Attributes Description
output * <optional>
The output of the handled data.
Returns:
The async process promise.
Type
Promise | void

run(command, optionsopt)

Source:
Inherited From:
Run node script in a new spawn shell.
Parameters:
Name Type Attributes Description
command string The command to run.
options * <optional>
The spawn options.
Returns:
The async process promise.
Type
Promise

(async) spawn(command, parametersopt, optionsopt)

Source:
Inherited From:
Run script in a new spawn shell.
Parameters:
Name Type Attributes Default Description
command string The binary that will execute the command.
parameters Array.<string> | string <optional>
'' The command.
options * <optional>
The spawn options.
Returns:
The async process promise.
Type
Promise

call(command, internalopt)

Source:
Inherited From:
Call an existing command.
Parameters:
Name Type Attributes Default Description
command string Command to call.
internal boolean <optional>
true Specify if the command should be processed as an internal process. If if should check the policies restrictions, set to false.
Returns:
The async process promise.
Type
Promise

forwardCall(command, internalopt)

Source:
Inherited From:
Forward current command to another command with the exact same arguments.
Parameters:
Name Type Attributes Default Description
command string The command name that should be used instead of handling command.
internal boolean <optional>
true Specify if the command should be processed as an internal process. If if should check the policies restrictions, set to false.
Returns:
The async process promise.
Type
Promise

formatArguments()

Source:
Inherited From:
Format arguments from array descriptors to Argument instances.

makeArgument(Argument, data)

Source:
Inherited From:
Create an Argument instance from the given data.
Parameters:
Name Type Description
Argument function The argument class to use, either a Parameter, an Option or a Flag.
data console.models.Argument | Array.<*> | string The data to make as an argument.
Throws:
Indicates that the given data was invalid.
Type
TypeError
Returns:
The made argument instance.
Type
console.models.Argument

argument(type, name, fullopt)

Source:
Inherited From:
Get argument by type and name. Returns the argument value by default, but can returns the whole Argument instance.
Parameters:
Name Type Attributes Default Description
type string The argument type.
name string The argument name.
full boolean <optional>
false Indicates if a full argument should be returned instead of the value only.
Returns:
Either the argument value or the Argument instance.
Type
* | Argument

argumentIsSupported(type, name)

Source:
Inherited From:
Check if argument is supported by type and name.
Parameters:
Name Type Description
type string The argument type.
name string The argument name.
Returns:
The argument support in the current command.
Type
boolean

parameter(name)

Source:
Inherited From:
Get parameter by name.
Parameters:
Name Type Description
name string The parameter name.
Returns:
The parameter value.
Type
string

parameterIsSupported(name)

Source:
Inherited From:
Check if parameter is supported by name.
Parameters:
Name Type Description
name string The parameter name.
Returns:
The parameter support in the current command.
Type
boolean

option(name)

Source:
Inherited From:
Get option by name.
Parameters:
Name Type Description
name string The option name.
Returns:
The option value.
Type
string | null

optionIsSupported(name)

Source:
Inherited From:
Check if option is supported by name.
Parameters:
Name Type Description
name string The option name.
Returns:
The option support in the current command.
Type
boolean

flag(name)

Source:
Inherited From:
Get flag by name.
Parameters:
Name Type Description
name string The flag name.
Returns:
The flag value.
Type
boolean

flagIsSupported(name)

Source:
Inherited From:
Check if flag is supported by name.
Parameters:
Name Type Description
name string The flag name.
Returns:
The flag support in the current command.
Type
boolean

spam(…parameters)

Source:
Inherited From:
Print spammy message for developers.
Parameters:
Name Type Attributes Description
parameters * <repeatable>
Data to print as spam.

debug(…parameters)

Source:
Inherited From:
Print debug information.
Parameters:
Name Type Attributes Description
parameters * <repeatable>
Data to print as debug.

log(…parameters)

Source:
Inherited From:
Print log information.
Parameters:
Name Type Attributes Description
parameters * <repeatable>
Data to print as log.

info(…parameters)

Source:
Inherited From:
Print information.
Parameters:
Name Type Attributes Description
parameters * <repeatable>
Data to print as info.

success(…parameters)

Source:
Inherited From:
Print success message.
Parameters:
Name Type Attributes Description
parameters * <repeatable>
Data to print as success.

warning(…parameters)

Source:
Inherited From:
Print warning message.
Parameters:
Name Type Attributes Description
parameters * <repeatable>
Data to print as warning.

failure(…parameters)

Source:
Inherited From:
Print failure message.
Parameters:
Name Type Attributes Description
parameters * <repeatable>
Data to print as failure.

print(level, …parameters)

Source:
Inherited From:
Print information based on the print level and verbose level.
Parameters:
Name Type Attributes Description
level number The level of verbosity of the print.
parameters * <repeatable>
Data to print.

ask(question, defaultAnsweropt)

Source:
Inherited From:
Prompt the user with a question.
Parameters:
Name Type Attributes Default Description
question string The question to ask.
defaultAnswer string | null <optional>
null The default answer.
Returns:
The user answer.
Type
Promise.<string>

secret(question)

Source:
Inherited From:
Prompt the user with a question requesting hidden answer.
Parameters:
Name Type Description
question string The question to ask.
Returns:
The user answer.
Type
Promise.<string>

confirm(statement, defaultValueopt)

Source:
Inherited From:
Prompt the user with a confirmation statement requesting a yes/no answer.
Parameters:
Name Type Attributes Default Description
statement string The statement to be confirmed.
defaultValue boolean <optional>
false The default confirmation value.
Returns:
The user confirmation.
Type
Promise.<boolean>

choice(question, choices, defaultValueopt)

Source:
Inherited From:
Prompt the user with a question having a list of available choices.
Example
command.choice('What color?', ['Red', 'Green', Blue']); // Answer 'Blue' -> returns 'Blue'
command.choice('What size?', { s: 'Small', m: 'Medium', l: 'Large' }); // Answer 'Medium' -> returns 'l'
Parameters:
Name Type Attributes Description
question string The question to ask.
choices Array.<string> | object.<string, string> The available answers.
defaultValue string <optional>
The default answer.
Returns:
The user answer.
Type
Promise.<string>

table(header, data)

Source:
Inherited From:
Print a table with list of models.
Example
command.table(['Key', 'Value'], [['foo', 'bar'], ['baz', 'qux'], ['some key', 'some value']]);
Parameters:
Name Type Description
header Array.<string> The table header.
data Array.<Array.<string>> The table content.

tables(tables, sideBySideopt, optionsopt)

Source:
Inherited From:
Print multiple tables.
Parameters:
Name Type Attributes Description
tables Array.<*> The tables to print.
sideBySide boolean <optional>
If set to true, the tables will be printed side by side instead of one under the other.
options * <optional>
The table options.

initOutputInterceptor()

Source:
Inherited From:
Initialize the output interceptor callback for the terminal interceptor. Doesn't enable the interceptor.

captureOutput()

Source:
Inherited From:
Initialize the output capturing phase with the default output interceptor.
Returns:
The current command.
Type
console.Command

stopCaptureOutput()

Source:
Inherited From:
Stop the output capture by the default interceptor.
Returns:
The current command.
Type
console.Command

getCapturedOutput(stopCaptureopt)

Source:
Inherited From:
Get the captured output.
Parameters:
Name Type Attributes Default Description
stopCapture boolean <optional>
true Indicates if the capture should stop.
Returns:
The captured output.
Type
string

t(key, …parameters)

Source:
Inherited From:
Translate with the translator service. If it does not exist, returns the given string.
Parameters:
Name Type Attributes Description
key string The translation key to translate.
parameters * <repeatable>
Translator's translate parameters.
Returns:
The translated content.
Type
string

setYargs(yargs)

Source:
Inherited From:
Define the current Yargs instance.
Parameters:
Name Type Description
yargs yargs The Yargs instance.

setArgv(argv)

Source:
Inherited From:
Set the current arguments from the console. Those arguments should be processed by Yargs first.
Parameters:
Name Type Description
argv * The Yargs arguments.

buildYargsModel()

Source:
Inherited From:
Build yargs model.
Returns:
The Yargs model.
Type
Object