diff --git a/build/actions/device.js b/build/actions/device.js index 8f7f90fa..9b0e81c1 100644 --- a/build/actions/device.js +++ b/build/actions/device.js @@ -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); } diff --git a/doc/cli.markdown b/doc/cli.markdown index f80e9e7e..a12479f6 100644 --- a/doc/cli.markdown +++ b/doc/cli.markdown @@ -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 diff --git a/lib/actions/device.coffee b/lib/actions/device.coffee index 7e24aa56..4f0625d6 100644 --- a/lib/actions/device.coffee +++ b/lib/actions/device.coffee @@ -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'