Allow non-interactice config generate for simple network settings

Fixes #695
Fixes #410
Change-Type: minor
This commit is contained in:
Tim Perry 2017-11-14 14:14:53 +01:00
parent f7075d7db9
commit 87f46cb957
3 changed files with 75 additions and 5 deletions

View File

@ -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 <existingDeviceKey>\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 <existingDeviceKey>\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 {

View File

@ -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 &#60;network&#62;
the network type to use: ethernet or wifi
#### --wifiSsid &#60;wifiSsid&#62;
the wifi ssid to use (used only if --network is set to wifi)
#### --wifiKey &#60;wifiKey&#62;
the wifi key to use (used only if --network is set to wifi)
#### --appUpdatePollInterval &#60;appUpdatePollInterval&#62;
how frequently (in minutes) to poll for application updates
# Preload
## preload &#60;image&#62;

View File

@ -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)