Merge pull request #261 from resin-io/jviotti/feature/move-device

Implement device move command
This commit is contained in:
Juan Cruz Viotti 2015-11-12 08:32:55 -04:00
commit d1b25c17b6
8 changed files with 84 additions and 14 deletions

View File

@ -139,6 +139,25 @@
} }
}; };
exports.move = {
signature: 'device move <uuid>',
description: 'move a device to another application',
help: 'Use this command to move a device to another application you own.\n\nIf you omit the application, you\'ll get asked for it interactively.\n\nExamples:\n\n $ resin device move 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9\n $ resin device move 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9 --application MyNewApp',
permission: 'user',
options: [commandOptions.optionalApplication],
action: function(params, options, done) {
return resin.models.device.get(params.uuid).then(function(device) {
return options.application || patterns.selectApplication(function(application) {
return _.all([application.device_type === device.device_type, device.application_name !== application.app_name]);
});
}).tap(function(application) {
return resin.models.device.move(params.uuid, application);
}).then(function(application) {
return console.info(params.uuid + " was moved to " + application);
}).nodeify(done);
}
};
exports.init = { exports.init = {
signature: 'device init', signature: 'device init',
description: 'initialise a device with resin os', description: 'initialise a device with resin os',

View File

@ -70,6 +70,8 @@
capitano.command(actions.device.register); capitano.command(actions.device.register);
capitano.command(actions.device.move);
capitano.command(actions.device.info); capitano.command(actions.device.info);
capitano.command(actions.notes.set); capitano.command(actions.notes.set);

View File

@ -42,17 +42,17 @@
}); });
}; };
exports.selectApplication = function() { exports.selectApplication = function(filter) {
return resin.models.application.hasAny().then(function(hasAnyApplications) { return resin.models.application.hasAny().then(function(hasAnyApplications) {
if (!hasAnyApplications) { if (!hasAnyApplications) {
throw new Error('You don\'t have any applications'); throw new Error('You don\'t have any applications');
} }
return resin.models.application.getAll().then(function(applications) { return resin.models.application.getAll();
return form.ask({ }).filter(filter || _.constant(true)).then(function(applications) {
message: 'Select an application', return form.ask({
type: 'list', message: 'Select an application',
choices: _.pluck(applications, 'app_name') type: 'list',
}); choices: _.pluck(applications, 'app_name')
}); });
}); });
}; };

View File

@ -37,6 +37,7 @@ Now you have access to all the commands referenced below.
- [device rm &#60;uuid&#62;](#device-rm-60-uuid-62-) - [device rm &#60;uuid&#62;](#device-rm-60-uuid-62-)
- [device identify &#60;uuid&#62;](#device-identify-60-uuid-62-) - [device identify &#60;uuid&#62;](#device-identify-60-uuid-62-)
- [device rename &#60;uuid&#62; [newName]](#device-rename-60-uuid-62-newname-) - [device rename &#60;uuid&#62; [newName]](#device-rename-60-uuid-62-newname-)
- [device move &#60;uuid&#62;](#device-move-60-uuid-62-)
- [device init](#device-init) - [device init](#device-init)
- Environment Variables - Environment Variables
@ -288,6 +289,23 @@ Examples:
$ resin device rename 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9 MyPi $ resin device rename 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9 MyPi
$ resin device rename 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9 $ resin device rename 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9
## device move &#60;uuid&#62;
Use this command to move a device to another application you own.
If you omit the application, you'll get asked for it interactively.
Examples:
$ resin device move 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9
$ resin device move 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9 --application MyNewApp
### Options
#### --application, --a,app, --a,app &#60;application&#62;
application name
## device init ## device init
Use this command to download the OS image of a certain application and write it to an SD Card. Use this command to download the OS image of a certain application and write it to an SD Card.

View File

@ -181,6 +181,34 @@ exports.rename =
events.send('device.rename', device: params.uuid) events.send('device.rename', device: params.uuid)
.nodeify(done) .nodeify(done)
exports.move =
signature: 'device move <uuid>'
description: 'move a device to another application'
help: '''
Use this command to move a device to another application you own.
If you omit the application, you'll get asked for it interactively.
Examples:
$ resin device move 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9
$ resin device move 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9 --application MyNewApp
'''
permission: 'user'
options: [ commandOptions.optionalApplication ]
action: (params, options, done) ->
resin.models.device.get(params.uuid).then (device) ->
return options.application or patterns.selectApplication (application) ->
return _.all [
application.device_type is device.device_type
device.application_name isnt application.app_name
]
.tap (application) ->
return resin.models.device.move(params.uuid, application)
.then (application) ->
console.info("#{params.uuid} was moved to #{application}")
.nodeify(done)
exports.init = exports.init =
signature: 'device init' signature: 'device init'
description: 'initialise a device with resin os' description: 'initialise a device with resin os'

View File

@ -47,6 +47,7 @@ capitano.command(actions.device.init)
capitano.command(actions.device.remove) capitano.command(actions.device.remove)
capitano.command(actions.device.identify) capitano.command(actions.device.identify)
capitano.command(actions.device.register) capitano.command(actions.device.register)
capitano.command(actions.device.move)
capitano.command(actions.device.info) capitano.command(actions.device.info)
# ---------- Notes Module ---------- # ---------- Notes Module ----------

View File

@ -24,16 +24,18 @@ exports.confirm = (yesOption, message) ->
if not confirmed if not confirmed
throw new Error('Aborted') throw new Error('Aborted')
exports.selectApplication = -> exports.selectApplication = (filter) ->
resin.models.application.hasAny().then (hasAnyApplications) -> resin.models.application.hasAny().then (hasAnyApplications) ->
if not hasAnyApplications if not hasAnyApplications
throw new Error('You don\'t have any applications') throw new Error('You don\'t have any applications')
resin.models.application.getAll().then (applications) -> return resin.models.application.getAll()
return form.ask .filter(filter or _.constant(true))
message: 'Select an application' .then (applications) ->
type: 'list' return form.ask
choices: _.pluck(applications, 'app_name') message: 'Select an application'
type: 'list'
choices: _.pluck(applications, 'app_name')
exports.selectOrCreateApplication = -> exports.selectOrCreateApplication = ->
resin.models.application.hasAny().then (hasAnyApplications) -> resin.models.application.hasAny().then (hasAnyApplications) ->

View File

@ -58,7 +58,7 @@
"resin-image": "^1.1.4", "resin-image": "^1.1.4",
"resin-image-manager": "^3.2.2", "resin-image-manager": "^3.2.2",
"resin-pine": "^1.3.0", "resin-pine": "^1.3.0",
"resin-sdk": "^4.0.0", "resin-sdk": "^4.1.1",
"resin-settings-client": "^3.1.0", "resin-settings-client": "^3.1.0",
"resin-vcs": "^2.0.0", "resin-vcs": "^2.0.0",
"rimraf": "^2.4.3", "rimraf": "^2.4.3",