Allow passing a custom uuid to device register

This commit is contained in:
Juan Cruz Viotti 2015-10-19 14:16:47 -04:00
parent f6d2043747
commit d28ecf3230
3 changed files with 26 additions and 2 deletions

View File

@ -70,9 +70,19 @@
description: 'register a device',
help: 'Use this command to register a device to an application.\n\nExamples:\n\n $ resin device register MyApp',
permission: 'user',
options: [
{
signature: 'uuid',
description: 'custom uuid',
parameter: 'uuid',
alias: 'u'
}
],
action: function(params, options, done) {
return resin.models.application.get(params.application).then(function(application) {
return resin.models.device.generateUUID().then(function(uuid) {
return Promise["try"](function() {
return options.uuid || resin.models.device.generateUUID();
}).then(function(uuid) {
console.info("Registering to " + application.app_name + ": " + uuid);
return resin.models.device.register(application.app_name, uuid);
});

View File

@ -250,6 +250,12 @@ Examples:
$ resin device register MyApp
### Options
#### --uuid, -u <uuid>
custom uuid
## device rm <uuid>
Use this command to remove a device from resin.io.

View File

@ -98,10 +98,18 @@ exports.register =
$ resin device register MyApp
'''
permission: 'user'
options: [
signature: 'uuid'
description: 'custom uuid'
parameter: 'uuid'
alias: 'u'
]
action: (params, options, done) ->
resin.models.application.get(params.application).then (application) ->
resin.models.device.generateUUID().then (uuid) ->
Promise.try ->
return options.uuid or resin.models.device.generateUUID()
.then (uuid) ->
console.info("Registering to #{application.app_name}: #{uuid}")
return resin.models.device.register(application.app_name, uuid)
.get('uuid')