Implement device await command

This commit is contained in:
Juan Cruz Viotti 2015-05-05 02:08:11 -03:00
parent 144a155208
commit 4c5d5697bc
6 changed files with 102 additions and 1 deletions

View File

@ -118,6 +118,42 @@
} }
}; };
exports.await = {
signature: 'device await <name>',
description: 'await for a device to become online',
help: 'Use this command to await for a device to become online.\n\nThe process will exit when the device becomes online.\n\nNotice that there is no time limit for this command, so it might run forever.\n\nYou can configure the poll interval with the --interval option (defaults to 3000ms).\n\nExamples:\n\n $ resin device await MyDevice\n $ resin device await MyDevice --interval 1000',
options: [
{
signature: 'interval',
parameter: 'interval',
description: 'poll interval',
alias: 'i'
}
],
permission: 'user',
action: function(params, options, done) {
var poll;
if (options.interval == null) {
options.interval = 3000;
}
poll = function() {
return resin.models.device.isOnline(params.name, function(error, isOnline) {
if (error != null) {
return done(error);
}
if (isOnline) {
console.info("Device became online: " + params.name);
return done();
} else {
console.info("Polling device network status: " + params.name);
return setTimeout(poll, options.interval);
}
});
};
return poll();
}
};
exports.init = { exports.init = {
signature: 'device init [device]', signature: 'device init [device]',
description: 'initialise a device with resin os', description: 'initialise a device with resin os',

View File

@ -102,6 +102,8 @@
capitano.command(actions.device.identify); capitano.command(actions.device.identify);
capitano.command(actions.device.await);
capitano.command(actions.drive.list); capitano.command(actions.drive.list);
capitano.command(actions.notes.set); capitano.command(actions.notes.set);

View File

@ -39,6 +39,7 @@ Now you have access to all the commands referenced below.
- [device identify &#60;uuid&#62;](#/pages/using/cli.md#device-identify-60-uuid-62-) - [device identify &#60;uuid&#62;](#/pages/using/cli.md#device-identify-60-uuid-62-)
- [device rename &#60;name&#62; [newName]](#/pages/using/cli.md#device-rename-60-name-62-newname-) - [device rename &#60;name&#62; [newName]](#/pages/using/cli.md#device-rename-60-name-62-newname-)
- [devices supported](#/pages/using/cli.md#devices-supported) - [devices supported](#/pages/using/cli.md#devices-supported)
- [device await &#60;name&#62;](#/pages/using/cli.md#device-await-60-name-62-)
- [device init [device]](#/pages/using/cli.md#device-init-device-) - [device init [device]](#/pages/using/cli.md#device-init-device-)
- Drive - Drive
@ -334,6 +335,27 @@ Examples:
$ resin devices supported $ resin devices supported
## device await &#60;name&#62;
Use this command to await for a device to become online.
The process will exit when the device becomes online.
Notice that there is no time limit for this command, so it might run forever.
You can configure the poll interval with the --interval option (defaults to 3000ms).
Examples:
$ resin device await MyDevice
$ resin device await MyDevice --interval 1000
### Options
#### --interval, -i &#60;interval&#62;
poll interval
## device init [device] ## device init [device]
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

@ -163,6 +163,46 @@ exports.supported =
_.each(devices, _.unary(console.log)) _.each(devices, _.unary(console.log))
done() done()
exports.await =
signature: 'device await <name>'
description: 'await for a device to become online'
help: '''
Use this command to await for a device to become online.
The process will exit when the device becomes online.
Notice that there is no time limit for this command, so it might run forever.
You can configure the poll interval with the --interval option (defaults to 3000ms).
Examples:
$ resin device await MyDevice
$ resin device await MyDevice --interval 1000
'''
options: [
signature: 'interval'
parameter: 'interval'
description: 'poll interval'
alias: 'i'
]
permission: 'user'
action: (params, options, done) ->
options.interval ?= 3000
poll = ->
resin.models.device.isOnline params.name, (error, isOnline) ->
return done(error) if error?
if isOnline
console.info("Device became online: #{params.name}")
return done()
else
console.info("Polling device network status: #{params.name}")
setTimeout(poll, options.interval)
poll()
exports.init = exports.init =
signature: 'device init [device]' signature: 'device init [device]'
description: 'initialise a device with resin os' description: 'initialise a device with resin os'

View File

@ -74,6 +74,7 @@ capitano.command(actions.device.init)
capitano.command(actions.device.info) capitano.command(actions.device.info)
capitano.command(actions.device.remove) capitano.command(actions.device.remove)
capitano.command(actions.device.identify) capitano.command(actions.device.identify)
capitano.command(actions.device.await)
# ---------- Drive Module ---------- # ---------- Drive Module ----------
capitano.command(actions.drive.list) capitano.command(actions.drive.list)

View File

@ -63,7 +63,7 @@
"president": "^1.0.0", "president": "^1.0.0",
"progress-stream": "^0.5.0", "progress-stream": "^0.5.0",
"resin-cli-visuals": "^0.1.0", "resin-cli-visuals": "^0.1.0",
"resin-sdk": "^1.3.4", "resin-sdk": "^1.4.0",
"resin-settings-client": "^1.0.0", "resin-settings-client": "^1.0.0",
"resin-vcs": "^1.2.0", "resin-vcs": "^1.2.0",
"tmp": "^0.0.25", "tmp": "^0.0.25",