-
Notifications
You must be signed in to change notification settings - Fork 4
Command Example
axios edited this page Feb 7, 2021
·
2 revisions
'use strict';
const { Command } = require('@axiosleo/cli-tool');
class CommandExample extends Command {
constructor() {
super({
name: 'command-name',
desc: 'command desc',
alias: ['command-alia1','command-alia2', ...],
args: [
{
name: 'name', // argument name
mode: 'optional', // required | optional
desc: 'arg desc',
default: null // only supported optional mode
}
],
options: [
{
name: 'name', // option name
short: 'n', // like 'n'
mode: 'optional', // required | optional
desc: 'option desc',
default: null // only supported optional mode
}
],
});
}
async exec(args, options, argList, app) {
// do something in here
// get arg&option by name
const arg1 = args.argName;
const option1 = options.optionName;
// get arg by index
const arg2 = argList[index];
// ask for answer
const answer = await this.ask('Please input your answer');
// ask for confirm, default value is 'false'
const confirm = await this.confirm('Confirm do this now?', false);
}
}
module.exports = CommandExample;Anything unclear or inaccurate? Please let me know at axioscros@aliyun.com