Comparing version 1.1.1 to 1.1.2
@@ -13,3 +13,3 @@ #!/usr/bin/env node | ||
}) | ||
.option('-t', 'switch') | ||
.option('-t', { command: '', type: 'switch' }) | ||
.command('start', function (cmd, t) { | ||
@@ -16,0 +16,0 @@ console.log('cmd:', t); |
@@ -99,2 +99,5 @@ const Class = require('cify').Class; | ||
}.bind(this)); | ||
if (utils.isString(setting.command)) { | ||
setting.command = new RegExp('^' + setting.command + '$'); | ||
} | ||
//处理 setting 结束 | ||
@@ -110,3 +113,5 @@ names = utils.isArray(names) ? names : [names]; | ||
//option 的 handle 不能自行配置,只要出现包含的选项,就会执行 | ||
this.handle({ options: [name] }, fn); | ||
var _pattern = utils.copy(setting); | ||
_pattern.options = [name]; | ||
this.handle(_pattern, fn); | ||
}, this); | ||
@@ -167,3 +172,4 @@ return this; | ||
this.option(['-v', '--version'], { | ||
type: 'switch' | ||
type: 'switch', | ||
command: '' | ||
}, function ($self) { | ||
@@ -182,3 +188,4 @@ $self._console.log($self._version || 'unknow'); | ||
this.option(['-h', '--help'], { | ||
type: 'switch' | ||
type: 'switch', | ||
command: '' | ||
}, function ($self) { | ||
@@ -314,4 +321,7 @@ $self._console.log($self._help || 'unknow'); | ||
var setting = this._options[token]; | ||
//如果「选项」不存在,添加到 invalidOptions | ||
if (utils.isNull(setting)) { | ||
//如果「选项」不存在,或限定的 command 不匹配,添加到 invalidOptions | ||
if ( | ||
utils.isNull(setting) || | ||
(setting.command && !setting.command.test(this._command || '')) | ||
) { | ||
invalidOptions.push(token); | ||
@@ -322,6 +332,7 @@ continue; | ||
var nextToken = this._tokens[index]; | ||
if ((!OPTION_REGEXP.test(nextToken) || setting.greed) && | ||
(!setting.regexp || setting.regexp.test(nextToken))) { | ||
var value = utils.isNull(nextToken) ? | ||
setting.default : nextToken.toString(); | ||
if ( | ||
(!OPTION_REGEXP.test(nextToken) || setting.greed) && | ||
(!setting.regexp || setting.regexp.test(nextToken)) | ||
) { | ||
var value = utils.isNull(nextToken) ? setting.default : nextToken.toString(); | ||
this.options[token] = setting.convert ? setting.convert(value) : value; | ||
@@ -328,0 +339,0 @@ } else { |
{ | ||
"name": "cmdline", | ||
"rawName": "cmdline", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "cmdline is a process.argv parser", | ||
@@ -6,0 +6,0 @@ "main": "./lib/index.js", |
15819
497