From 87f46cb9576c23c4e028b05d7616736e6286c325 Mon Sep 17 00:00:00 2001 From: Tim Perry Date: Tue, 14 Nov 2017 14:14:53 +0100 Subject: [PATCH] Allow non-interactice config generate for simple network settings Fixes #695 Fixes #410 Change-Type: minor --- build/actions/config.js | 24 ++++++++++++++++++++++-- doc/cli.markdown | 23 ++++++++++++++++++++++- lib/actions/config.coffee | 33 +++++++++++++++++++++++++++++++-- 3 files changed, 75 insertions(+), 5 deletions(-) diff --git a/build/actions/config.js b/build/actions/config.js index 5c34ad4d..c835864e 100644 --- a/build/actions/config.js +++ b/build/actions/config.js @@ -194,7 +194,7 @@ exports.reconfigure = { exports.generate = { signature: 'config generate', description: 'generate a config.json file', - help: 'Use this command to generate a config.json for a device or application\n\nExamples:\n\n $ resin config generate --device 7cf02a6\n $ resin config generate --device 7cf02a6 --device-api-key \n $ resin config generate --device 7cf02a6 --output config.json\n $ resin config generate --app MyApp\n $ resin config generate --app MyApp --output config.json', + help: 'Use this command to generate a config.json for a device or application.\n\nThis is interactive by default, but you can do this automatically without interactivity\nby specifying an option for each question on the command line, if you know the questions\nthat will be asked for the relevant device type.\n\nExamples:\n\n $ resin config generate --device 7cf02a6\n $ resin config generate --device 7cf02a6 --device-api-key \n $ resin config generate --device 7cf02a6 --output config.json\n $ resin config generate --app MyApp\n $ resin config generate --app MyApp --output config.json\n $ resin config generate --app MyApp --network wifi --wifiSsid mySsid --wifiKey abcdefgh --appUpdatePollInterval 1', options: [ commandOptions.optionalApplication, commandOptions.optionalDevice, { signature: 'deviceApiKey', @@ -206,6 +206,22 @@ exports.generate = { description: 'output', parameter: 'output', alias: 'o' + }, { + signature: 'network', + description: 'the network type to use: ethernet or wifi', + parameter: 'network' + }, { + signature: 'wifiSsid', + description: 'the wifi ssid to use (used only if --network is set to wifi)', + parameter: 'wifiSsid' + }, { + signature: 'wifiKey', + description: 'the wifi key to use (used only if --network is set to wifi)', + parameter: 'wifiKey' + }, { + signature: 'appUpdatePollInterval', + description: 'how frequently (in minutes) to poll for application updates', + parameter: 'appUpdatePollInterval' } ], permission: 'user', @@ -228,7 +244,11 @@ exports.generate = { } return resin.models.application.get(options.application); }).then(function(resource) { - return resin.models.device.getManifestBySlug(resource.device_type).get('options').then(form.run).then(function(answers) { + return resin.models.device.getManifestBySlug(resource.device_type).get('options').then(function(formOptions) { + return form.run(formOptions, { + override: options + }); + }).then(function(answers) { if (resource.uuid != null) { return generateDeviceConfig(resource, options.deviceApiKey, answers); } else { diff --git a/doc/cli.markdown b/doc/cli.markdown index d969ac79..e4171a1c 100644 --- a/doc/cli.markdown +++ b/doc/cli.markdown @@ -1041,7 +1041,11 @@ show advanced commands ## config generate -Use this command to generate a config.json for a device or application +Use this command to generate a config.json for a device or application. + +This is interactive by default, but you can do this automatically without interactivity +by specifying an option for each question on the command line, if you know the questions +that will be asked for the relevant device type. Examples: @@ -1050,6 +1054,7 @@ Examples: $ resin config generate --device 7cf02a6 --output config.json $ resin config generate --app MyApp $ resin config generate --app MyApp --output config.json + $ resin config generate --app MyApp --network wifi --wifiSsid mySsid --wifiKey abcdefgh --appUpdatePollInterval 1 ### Options @@ -1069,6 +1074,22 @@ custom device key - note that this is only supported on ResinOS 2.0.3+ output +#### --network <network> + +the network type to use: ethernet or wifi + +#### --wifiSsid <wifiSsid> + +the wifi ssid to use (used only if --network is set to wifi) + +#### --wifiKey <wifiKey> + +the wifi key to use (used only if --network is set to wifi) + +#### --appUpdatePollInterval <appUpdatePollInterval> + +how frequently (in minutes) to poll for application updates + # Preload ## preload <image> diff --git a/lib/actions/config.coffee b/lib/actions/config.coffee index f112c37c..89fa06a4 100644 --- a/lib/actions/config.coffee +++ b/lib/actions/config.coffee @@ -219,7 +219,11 @@ exports.generate = signature: 'config generate' description: 'generate a config.json file' help: ''' - Use this command to generate a config.json for a device or application + Use this command to generate a config.json for a device or application. + + This is interactive by default, but you can do this automatically without interactivity + by specifying an option for each question on the command line, if you know the questions + that will be asked for the relevant device type. Examples: @@ -228,6 +232,7 @@ exports.generate = $ resin config generate --device 7cf02a6 --output config.json $ resin config generate --app MyApp $ resin config generate --app MyApp --output config.json + $ resin config generate --app MyApp --network wifi --wifiSsid mySsid --wifiKey abcdefgh --appUpdatePollInterval 1 ''' options: [ commandOptions.optionalApplication @@ -244,6 +249,27 @@ exports.generate = parameter: 'output' alias: 'o' } + # Options for non-interactive configuration + { + signature: 'network' + description: 'the network type to use: ethernet or wifi' + parameter: 'network' + } + { + signature: 'wifiSsid' + description: 'the wifi ssid to use (used only if --network is set to wifi)' + parameter: 'wifiSsid' + } + { + signature: 'wifiKey' + description: 'the wifi key to use (used only if --network is set to wifi)' + parameter: 'wifiKey' + } + { + signature: 'appUpdatePollInterval' + description: 'how frequently (in minutes) to poll for application updates' + parameter: 'appUpdatePollInterval' + } ] permission: 'user' action: (params, options, done) -> @@ -272,7 +298,10 @@ exports.generate = .then (resource) -> resin.models.device.getManifestBySlug(resource.device_type) .get('options') - .then(form.run) + .then (formOptions) -> + # Pass params as an override: if there is any param with exactly the same name as a + # required option, that value is used (and the corresponding question is not asked) + form.run(formOptions, override: options) .then (answers) -> if resource.uuid? generateDeviceConfig(resource, options.deviceApiKey, answers)