From 85444a5a6aecbbe75c638c3722e436483259c2a3 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Mon, 20 Apr 2015 09:06:40 -0400 Subject: [PATCH] Make os download command accept an application name instead of id --- build/actions/os.js | 93 +++++++++++++++++++++++-------------------- lib/actions/os.coffee | 89 +++++++++++++++++++++-------------------- 2 files changed, 95 insertions(+), 87 deletions(-) diff --git a/build/actions/os.js b/build/actions/os.js index 7043264b..1a4373d9 100644 --- a/build/actions/os.js +++ b/build/actions/os.js @@ -26,9 +26,9 @@ elevate = require('../elevate'); exports.download = { - signature: 'os download ', + signature: 'os download ', 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: [ commandOptions.network, commandOptions.wifiSsid, commandOptions.wifiKey, { signature: 'output', @@ -40,51 +40,56 @@ ], permission: 'user', action: function(params, options, done) { - var osParams; - osParams = { - network: options.network, - wifiSsid: options.ssid, - wifiKey: options.key, - appId: params.id - }; - return async.waterfall([ - function(callback) { - if (osParams.network != null) { - return callback(); - } - return visuals.patterns.selectNetworkParameters(function(error, parameters) { - if (error != null) { - return callback(error); - } - _.extend(osParams, parameters); - return callback(); - }); - }, function(callback) { - return mkdirp(path.dirname(options.output), _.unary(callback)); - }, function(callback) { - var bar, spinner; - console.info("Destination file: " + options.output + "\n"); - bar = new visuals.widgets.Progress('Downloading Device OS'); - spinner = new visuals.widgets.Spinner('Downloading Device OS (size unknown)'); - return resin.models.os.download(osParams, options.output, function(error) { - spinner.stop(); - if (error != null) { - return callback(error); - } - }, function(state) { - if (state != null) { - return bar.update(state); - } else { - return spinner.start(); - } - }); - } - ], function(error) { + return resin.models.application.get(params.name, function(error, application) { + var osParams; if (error != null) { return done(error); } - console.info("\nFinished downloading " + options.output); - return done(null, options.output); + osParams = { + network: options.network, + wifiSsid: options.ssid, + wifiKey: options.key, + appId: application.id + }; + return async.waterfall([ + function(callback) { + if (osParams.network != null) { + return callback(); + } + return visuals.patterns.selectNetworkParameters(function(error, parameters) { + if (error != null) { + return callback(error); + } + _.extend(osParams, parameters); + return callback(); + }); + }, function(callback) { + return mkdirp(path.dirname(options.output), _.unary(callback)); + }, function(callback) { + var bar, spinner; + console.info("Destination file: " + options.output + "\n"); + bar = new visuals.widgets.Progress('Downloading Device OS'); + spinner = new visuals.widgets.Spinner('Downloading Device OS (size unknown)'); + return resin.models.os.download(osParams, options.output, function(error) { + spinner.stop(); + if (error != null) { + return callback(error); + } + }, function(state) { + if (state != null) { + return bar.update(state); + } else { + return spinner.start(); + } + }); + } + ], function(error) { + if (error != null) { + return done(error); + } + console.info("\nFinished downloading " + options.output); + return done(null, options.output); + }); }); } }; diff --git a/lib/actions/os.coffee b/lib/actions/os.coffee index 589a7d5b..d3e5050a 100644 --- a/lib/actions/os.coffee +++ b/lib/actions/os.coffee @@ -12,7 +12,7 @@ updateActions = require('./update') elevate = require('../elevate') exports.download = - signature: 'os download ' + signature: 'os download ' description: 'download device OS' help: ''' Use this command to download the device OS configured to a specific network. @@ -30,10 +30,10 @@ exports.download = Examples: - $ resin os download 91 --output ~/MyResinOS.zip - $ resin os download 91 --network ethernet --output ~/MyResinOS.zip - $ resin os download 91 --network wifi --ssid MyNetwork --key secreykey123 --output ~/MyResinOS.zip - $ resin os download 91 --network ethernet --output ~/MyResinOS.zip + $ resin os download MyApp --output ~/MyResinOS.zip + $ resin os download MyApp --network ethernet --output ~/MyResinOS.zip + $ resin os download MyApp --network wifi --ssid MyNetwork --key secreykey123 --output ~/MyResinOS.zip + $ resin os download MyApp --network ethernet --output ~/MyResinOS.zip ''' options: [ commandOptions.network @@ -50,45 +50,48 @@ exports.download = ] permission: 'user' action: (params, options, done) -> - osParams = - network: options.network - wifiSsid: options.ssid - wifiKey: options.key - appId: params.id - - async.waterfall [ - - (callback) -> - return callback() if osParams.network? - visuals.patterns.selectNetworkParameters (error, parameters) -> - return callback(error) if error? - _.extend(osParams, parameters) - return callback() - - (callback) -> - - # We need to ensure this directory exists - mkdirp(path.dirname(options.output), _.unary(callback)) - - (callback) -> - console.info("Destination file: #{options.output}\n") - - bar = new visuals.widgets.Progress('Downloading Device OS') - spinner = new visuals.widgets.Spinner('Downloading Device OS (size unknown)') - - resin.models.os.download osParams, options.output, (error) -> - spinner.stop() - return callback(error) if error? - , (state) -> - if state? - bar.update(state) - else - spinner.start() - - ], (error) -> + resin.models.application.get params.name, (error, application) -> return done(error) if error? - console.info("\nFinished downloading #{options.output}") - return done(null, options.output) + + osParams = + network: options.network + wifiSsid: options.ssid + wifiKey: options.key + appId: application.id + + async.waterfall [ + + (callback) -> + return callback() if osParams.network? + visuals.patterns.selectNetworkParameters (error, parameters) -> + return callback(error) if error? + _.extend(osParams, parameters) + return callback() + + (callback) -> + + # We need to ensure this directory exists + mkdirp(path.dirname(options.output), _.unary(callback)) + + (callback) -> + console.info("Destination file: #{options.output}\n") + + bar = new visuals.widgets.Progress('Downloading Device OS') + spinner = new visuals.widgets.Spinner('Downloading Device OS (size unknown)') + + resin.models.os.download osParams, options.output, (error) -> + spinner.stop() + return callback(error) if error? + , (state) -> + if state? + bar.update(state) + else + spinner.start() + + ], (error) -> + return done(error) if error? + console.info("\nFinished downloading #{options.output}") + return done(null, options.output) exports.install = signature: 'os install [device]'