Implement --version/-v global options. Closes #35

This commit is contained in:
Juan Cruz Viotti 2015-04-30 11:56:15 -04:00
parent 361e149063
commit 7f7ca13001
4 changed files with 27 additions and 5 deletions

View File

@ -7,8 +7,9 @@
signature: 'version', signature: 'version',
description: 'output the version number', description: 'output the version number',
help: 'Display the Resin CLI version.', help: 'Display the Resin CLI version.',
action: function() { action: function(params, options, done) {
return console.log(packageJSON.version); console.log(packageJSON.version);
return done();
} }
}; };

View File

@ -49,6 +49,13 @@
alias: 'j' alias: 'j'
}); });
capitano.globalOption({
signature: 'version',
description: actions.info.version.description,
boolean: true,
alias: 'v'
});
capitano.globalOption({ capitano.globalOption({
signature: 'no-color', signature: 'no-color',
description: 'disable colour highlighting', description: 'disable colour highlighting',
@ -161,7 +168,11 @@
if (cli.global.project != null) { if (cli.global.project != null) {
changeProjectDirectory(cli.global.project); changeProjectDirectory(cli.global.project);
} }
return capitano.execute(cli, callback); if (cli.global.version) {
return actions.info.version.action(null, null, callback);
} else {
return capitano.execute(cli, callback);
}
} }
], errors.handle); ], errors.handle);

View File

@ -6,5 +6,6 @@ exports.version =
help: ''' help: '''
Display the Resin CLI version. Display the Resin CLI version.
''' '''
action: -> action: (params, options, done) ->
console.log(packageJSON.version) console.log(packageJSON.version)
return done()

View File

@ -31,6 +31,12 @@ capitano.globalOption
description: 'project path' description: 'project path'
alias: 'j' alias: 'j'
capitano.globalOption
signature: 'version'
description: actions.info.version.description
boolean: true
alias: 'v'
# We don't do anything in response to this options # We don't do anything in response to this options
# explicitly. We use InquirerJS to provide CLI widgets, # explicitly. We use InquirerJS to provide CLI widgets,
# and that module understands --no-color automatically. # and that module understands --no-color automatically.
@ -134,6 +140,9 @@ async.waterfall([
if cli.global.project? if cli.global.project?
changeProjectDirectory(cli.global.project) changeProjectDirectory(cli.global.project)
capitano.execute(cli, callback) if cli.global.version
actions.info.version.action(null, null, callback)
else
capitano.execute(cli, callback)
], errors.handle) ], errors.handle)