Make devices command list all devices if no application option. Closes #17

This commit is contained in:
Juan Cruz Viotti 2015-04-27 11:20:53 -04:00
parent 84900aa588
commit 9bb51d7146
3 changed files with 29 additions and 7 deletions

View File

@ -24,11 +24,17 @@
exports.list = {
signature: 'devices',
description: 'list all devices',
help: 'Use this command to list all devices that belong to a certain application.\n\nExamples:\n\n $ resin devices --application MyApp',
options: [commandOptions.application],
help: 'Use this command to list all devices that belong to you.\n\nYou can filter the devices by application by using the `--application` option.\n\nExamples:\n\n $ resin devices\n $ resin devices --application MyApp\n $ resin devices --app MyApp\n $ resin devices -a MyApp',
options: [commandOptions.optionalApplication],
permission: 'user',
action: function(params, options, done) {
return resin.models.device.getAllByApplication(options.application, function(error, devices) {
var getFunction;
if (options.application != null) {
getFunction = _.partial(resin.models.device.getAllByApplication, options.application);
} else {
getFunction = resin.models.device.getAll;
}
return getFunction(function(error, devices) {
if (error != null) {
return done(error);
}

View File

@ -262,11 +262,16 @@ Examples:
## devices
Use this command to list all devices that belong to a certain application.
Use this command to list all devices that belong to you.
You can filter the devices by application by using the `--application` option.
Examples:
$ resin devices
$ resin devices --application MyApp
$ resin devices --app MyApp
$ resin devices -a MyApp
### Options

View File

@ -16,16 +16,27 @@ exports.list =
signature: 'devices'
description: 'list all devices'
help: '''
Use this command to list all devices that belong to a certain application.
Use this command to list all devices that belong to you.
You can filter the devices by application by using the `--application` option.
Examples:
$ resin devices
$ resin devices --application MyApp
$ resin devices --app MyApp
$ resin devices -a MyApp
'''
options: [ commandOptions.application ]
options: [ commandOptions.optionalApplication ]
permission: 'user'
action: (params, options, done) ->
resin.models.device.getAllByApplication options.application, (error, devices) ->
if options.application?
getFunction = _.partial(resin.models.device.getAllByApplication, options.application)
else
getFunction = resin.models.device.getAll
getFunction (error, devices) ->
return done(error) if error?
console.log visuals.widgets.table.horizontal devices, [
'id'