Command
Definition
Locations
- Implementation:
src/commands
- Dependency Injection:
src/config/services/commands.js
- Dependency Injection CLI:
src/config/parameters/global/commands.js
API
Function | Usage |
---|---|
constructor() | Handles any dependency injection that can instantiated in the index or using tramway-core-dependency-injector |
action() | The main runner of the command, will be executed when the index maps the CLI to it. |
configure() | The configuration of the command, determines argument mapping and the order. Here is where InputOption objects are instantiated |
getArgument(name) | Does not need to be implemented, gives access to the value of the mapped argument. (See Input Option section) |
getOption(name) | Does not need to be implemented, gives access to the value of the option. (See Input Option section) |
To create a command, extend the class.
import { Command } from 'tramway-command';
Example
import { Command, commands } from 'tramway-command';const { InputOption } = commands;export default class MainCommand extends Command {configure() {this.args.add((new InputOption('input', InputOption.string)).isRequired());this.options.add(new InputOption('str', InputOption.string));this.options.add((new InputOption('num', InputOption.number)).isRequired());this.options.add(new InputOption('arr', InputOption.array));this.options.add(new InputOption('bool', InputOption.boolean));}action() {console.log("Test command ran, here's some of what you gave it", this.arguments, this.options);}}
Dependency Injection
Services
import {MainCommand,} from '../../command';export default {"command.main": {"class": MainCommand,"constructor": [],"functions": []},};
Parameters
export default {"main:command": 'command.main'};