-
-
Notifications
You must be signed in to change notification settings - Fork 133
Dev Documentation
Joel Cox edited this page May 30, 2015
·
4 revisions
#aurelia-command API
Here is the suggested syntax. This syntax has been applid to the refactor(commands)
PR.
The second example contains a description on aurelia-command
's API
##Usage
import {command, option, alias, arg, description, instance} from 'aurelia-command';
import {parseList} from '../lib/util';
import Bundler from '../lib/bundler';
@command('bundle')
@arg('[type]')
@alias('b')
@option('-a, --add', 'Your Decription')
@option('-l, --list', 'Your Decription', parseList)
@description('Information about the command')
@instance(Bundler)
export default class BundleCommand{
constructor(config, logger, bundler) {
this.globalConfig = config;
this.logger = logger;
this.bundler = bundler;
}
canExecute(argv){}
beforeAction(argv, options){}
action(argv, options, beforeResult){}
afterAction(argv, options, actionResult){}
onError(){}
help(){}
}
##Descriptions
import {command, option, alias, arg, description, instance} from 'aurelia-command';
import {parseList} from '../lib/util';
import Bundler from '../lib/bundler';
@command('bundle')
// In Commanderjs to specify args you would prefix the name in command(/*'name <arg>'*/)
// Here is how we will add arguments
@arg('[type]', '<name>')
@alias('b')
@option('-a, --add', 'Your Decription')
@option('-l, --list', 'Your Decription', parseList)
@description('Information about the command')
// Instance will Create an instance from the paramater, and pass this instance to the constructor
// When the instance is created it will pass the commandConfig, config, and logger.
@instance(Bundler)
export default class BundleCommand{
constructor(config, logger, bundler) {
this.globalConfig = config;
this.logger = logger;
this.bundler = bundler;
}
// canExecute will be invoked first...
// @return {Promise || boolean} If the promise result or return value is false. The Command will not be executed.
canExecute(argv){}
// beforeAction Will be called after canExecute passes.
// @argv {Object} Custom version or argv that is created for the specific command
// @options {Object} All the options for @option
beforeAction(argv, options){}
// action Will be called after beforeAction is resolved
// @argv {Object} Custom version or argv that is created for the specific command
// @options {Object} All the options for @option
// @beforeResult {Object} The resolved result from @beforeAction
action(argv, options, beforeResult){}
// afterAction Will be called after action is resolved
// @argv {Object} Custom version or argv that is created for the specific command
// @options {Object} All the options for @option
// @result {Object} The resolved result from @action
afterAction(argv, options, actionResult){}
// onError Will becalled if any catch is found in the promise chain
// @argv {Object} Custom version or argv that is created for the specific command
// @options {Object} All the options for @option
// @issue {Object} The catched issue from the promise chain
onError(argv, options, issue){}
// help will be called only if the user executes aurelia <commandId> --help
// @log {Function} console.log.bind(console)
// @argv {Object} Custom version or argv that is created for the specific command
// @options {Object} All the options for @option
help(log, argv, options){}
}