Package Exports
- @travetto/cli
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@travetto/cli) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Command Line Interface
CLI infrastructure for travetto framework
Install: @travetto/cli
npm install @travetto/cliThe cli is the primary structure for interacting with the external requirements of the framework. This can range from running tests, to running applications, to generating email templates. The main executable can be installed globally or locally. If installed globally and locally, it will defer to the local installation for execution.
As is the custom, modules are able to register their own cli extensions as scripts, whose name starts with cli-. These scripts are then picked up at runtime and all available options are provided when viewing the help documentation. The following are all the supported cli operations and the various settings they allow.
General
Terminal: General Usage
$ travetto travetto --help
Usage: [options] [command]
Options:
-V, --version output the version number
-h, --help display help for command
Commands:
echo [options] [args...]
clean [options]
compile [options]
doc [options]
test [options] [regexes...]
test:lerna [options]
help [command] display help for commandThis will show all the available options/choices that are exposed given the currently installed modules.
Extending
Extending the cli is fairly straightforward. It is built upon commander, with a plugin model that is extensible:
Code: Echo Plugin
import * as commander from 'commander';
import { BasePlugin } from '@travetto/cli/src/plugin-base';
/**
* `npx trv echo`
*
* Allows for cleaning of the cache dire
*/
export class CliEchoPlugin extends BasePlugin {
name = 'echo';
init(cmd: commander.Command) {
return cmd.arguments('[args...]')
.option('-u, --uppercase', 'Upper case', false);
}
async action(args: string[]) {
if (this._cmd.uppercase) {
args = args.map(x => x.toUpperCase());
}
console.log(args);
}
complete() {
return { '': ['--uppercase'] };
}
}With the corresponding output:
Terminal: Echo Plugin Help
$ travetto travetto echo --help
Usage: echo [options] [args...]
Options:
-u, --uppercase Upper case (default: false)
-h, --help display help for commandAnd actually using it:
Terminal: Echo Plugin Run
$ travetto travetto echo -u bOb rOb DRoP
[ 'BOB', 'ROB', 'DROP' ]