From f7256e99272edd5adf4280e29652ff0aa61099ce Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Mon, 20 Apr 2015 09:13:15 -0400 Subject: [PATCH] Make device init command take an application name instead of id --- build/actions/device.js | 19 ++++++++++++++----- lib/actions/device.coffee | 20 ++++++++++++-------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/build/actions/device.js b/build/actions/device.js index f24d5e57..2a88e4b2 100644 --- a/build/actions/device.js +++ b/build/actions/device.js @@ -111,19 +111,28 @@ exports.init = { signature: 'device init [device]', description: 'initialise a device with resin os', - help: 'Use this command to download the OS image of a certain application and write it to an SD Card.\n\nNote that this command requires admin privileges.\n\nIf `device` is omitted, you will be prompted to select a device interactively.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nYou can quiet the progress bar by passing the `--quiet` boolean option.\n\nYou may have to unmount the device before attempting this operation.\n\nYou need to configure the network type and other settings:\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\nYou can omit network related options to be asked about them interactively.\n\nExamples:\n\n $ resin device init\n $ resin device init --application 91\n $ resin device init --application 91 --network ethernet\n $ resin device init /dev/disk2 --application 91 --network wifi --ssid MyNetwork --key secret', + help: 'Use this command to download the OS image of a certain application and write it to an SD Card.\n\nNote that this command requires admin privileges.\n\nIf `device` is omitted, you will be prompted to select a device interactively.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nYou can quiet the progress bar by passing the `--quiet` boolean option.\n\nYou may have to unmount the device before attempting this operation.\n\nYou need to configure the network type and other settings:\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\nYou can omit network related options to be asked about them interactively.\n\nExamples:\n\n $ resin device init\n $ resin device init --application MyApp\n $ resin device init --application MyApp --network ethernet\n $ resin device init /dev/disk2 --application MyApp --network wifi --ssid MyNetwork --key secret', options: [commandOptions.optionalApplication, commandOptions.network, commandOptions.wifiSsid, commandOptions.wifiKey], permission: 'user', action: function(params, options, done) { - params.id = options.application; return async.waterfall([ function(callback) { if (options.application != null) { return callback(null, options.application); } - return vcs.getApplicationId(process.cwd(), callback); - }, function(applicationId, callback) { - params.id = applicationId; + return vcs.getApplicationId(process.cwd(), function(error, applicationId) { + if (error != null) { + return callback(error); + } + return resin.models.application.getById(applicationId, function(error, application) { + if (error != null) { + return callback(error); + } + return callback(null, application.app_name); + }); + }); + }, function(applicationName, callback) { + params.name = applicationName; if (params.device != null) { return callback(null, params.device); } diff --git a/lib/actions/device.coffee b/lib/actions/device.coffee index 7e638053..14fa9c41 100644 --- a/lib/actions/device.coffee +++ b/lib/actions/device.coffee @@ -178,9 +178,9 @@ exports.init = Examples: $ resin device init - $ resin device init --application 91 - $ resin device init --application 91 --network ethernet - $ resin device init /dev/disk2 --application 91 --network wifi --ssid MyNetwork --key secret + $ resin device init --application MyApp + $ resin device init --application MyApp --network ethernet + $ resin device init /dev/disk2 --application MyApp --network wifi --ssid MyNetwork --key secret ''' options: [ commandOptions.optionalApplication @@ -191,16 +191,20 @@ exports.init = permission: 'user' action: (params, options, done) -> - params.id = options.application - async.waterfall([ (callback) -> return callback(null, options.application) if options.application? - vcs.getApplicationId(process.cwd(), callback) - (applicationId, callback) -> - params.id = applicationId + # TODO: Extract this to vcs.getApplicationName() + vcs.getApplicationId process.cwd(), (error, applicationId) -> + return callback(error) if error? + resin.models.application.getById applicationId, (error, application) -> + return callback(error) if error? + return callback(null, application.app_name) + + (applicationName, callback) -> + params.name = applicationName return callback(null, params.device) if params.device? visuals.patterns.selectDrive(callback)