Make os download command accept an application name instead of id

This commit is contained in:
Juan Cruz Viotti 2015-04-20 09:06:40 -04:00
parent ac115c7ea3
commit 85444a5a6a
2 changed files with 95 additions and 87 deletions

View File

@ -26,9 +26,9 @@
elevate = require('../elevate'); elevate = require('../elevate');
exports.download = { exports.download = {
signature: 'os download <id>', signature: 'os download <name>',
description: 'download device OS', description: 'download device OS',
help: 'Use this command to download the device OS configured to a specific network.\n\nEthernet:\n You can setup the device OS to use ethernet by setting the `--network` option to "ethernet".\n\nWifi:\n You can setup the device OS to use wifi by setting the `--network` option to "wifi".\n If you set "network" to "wifi", you will need to specify the `--ssid` and `--key` option as well.\n\nAlternatively, you can omit all kind of network configuration options to configure interactively.\n\nYou have to specify an output location with the `--output` option.\n\nExamples:\n\n $ resin os download 91 --output ~/MyResinOS.zip\n $ resin os download 91 --network ethernet --output ~/MyResinOS.zip\n $ resin os download 91 --network wifi --ssid MyNetwork --key secreykey123 --output ~/MyResinOS.zip\n $ resin os download 91 --network ethernet --output ~/MyResinOS.zip', help: 'Use this command to download the device OS configured to a specific network.\n\nEthernet:\n You can setup the device OS to use ethernet by setting the `--network` option to "ethernet".\n\nWifi:\n You can setup the device OS to use wifi by setting the `--network` option to "wifi".\n If you set "network" to "wifi", you will need to specify the `--ssid` and `--key` option as well.\n\nAlternatively, you can omit all kind of network configuration options to configure interactively.\n\nYou have to specify an output location with the `--output` option.\n\nExamples:\n\n $ resin os download MyApp --output ~/MyResinOS.zip\n $ resin os download MyApp --network ethernet --output ~/MyResinOS.zip\n $ resin os download MyApp --network wifi --ssid MyNetwork --key secreykey123 --output ~/MyResinOS.zip\n $ resin os download MyApp --network ethernet --output ~/MyResinOS.zip',
options: [ options: [
commandOptions.network, commandOptions.wifiSsid, commandOptions.wifiKey, { commandOptions.network, commandOptions.wifiSsid, commandOptions.wifiKey, {
signature: 'output', signature: 'output',
@ -40,12 +40,16 @@
], ],
permission: 'user', permission: 'user',
action: function(params, options, done) { action: function(params, options, done) {
return resin.models.application.get(params.name, function(error, application) {
var osParams; var osParams;
if (error != null) {
return done(error);
}
osParams = { osParams = {
network: options.network, network: options.network,
wifiSsid: options.ssid, wifiSsid: options.ssid,
wifiKey: options.key, wifiKey: options.key,
appId: params.id appId: application.id
}; };
return async.waterfall([ return async.waterfall([
function(callback) { function(callback) {
@ -86,6 +90,7 @@
console.info("\nFinished downloading " + options.output); console.info("\nFinished downloading " + options.output);
return done(null, options.output); return done(null, options.output);
}); });
});
} }
}; };

View File

@ -12,7 +12,7 @@ updateActions = require('./update')
elevate = require('../elevate') elevate = require('../elevate')
exports.download = exports.download =
signature: 'os download <id>' signature: 'os download <name>'
description: 'download device OS' description: 'download device OS'
help: ''' help: '''
Use this command to download the device OS configured to a specific network. Use this command to download the device OS configured to a specific network.
@ -30,10 +30,10 @@ exports.download =
Examples: Examples:
$ resin os download 91 --output ~/MyResinOS.zip $ resin os download MyApp --output ~/MyResinOS.zip
$ resin os download 91 --network ethernet --output ~/MyResinOS.zip $ resin os download MyApp --network ethernet --output ~/MyResinOS.zip
$ resin os download 91 --network wifi --ssid MyNetwork --key secreykey123 --output ~/MyResinOS.zip $ resin os download MyApp --network wifi --ssid MyNetwork --key secreykey123 --output ~/MyResinOS.zip
$ resin os download 91 --network ethernet --output ~/MyResinOS.zip $ resin os download MyApp --network ethernet --output ~/MyResinOS.zip
''' '''
options: [ options: [
commandOptions.network commandOptions.network
@ -50,11 +50,14 @@ exports.download =
] ]
permission: 'user' permission: 'user'
action: (params, options, done) -> action: (params, options, done) ->
resin.models.application.get params.name, (error, application) ->
return done(error) if error?
osParams = osParams =
network: options.network network: options.network
wifiSsid: options.ssid wifiSsid: options.ssid
wifiKey: options.key wifiKey: options.key
appId: params.id appId: application.id
async.waterfall [ async.waterfall [