Auto-merge for PR #718 via VersionBot

Allow configuring images for both device and just applications
This commit is contained in:
resin-io-versionbot[bot] 2017-11-17 10:46:33 +00:00 committed by GitHub
commit 6217b4a6b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 127 additions and 58 deletions

View File

@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file
automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
This project adheres to [Semantic Versioning](http://semver.org/).
## v6.10.0 - 2017-11-17
* Allow `os configure` to configure for an app, not just a specific device #718 [Tim Perry]
* Print help even for expected errors #718 [Tim Perry]
## v6.9.0 - 2017-11-16
* Allow non-interactice config generate for simple network settings #714 [Tim Perry]

View File

@ -44,6 +44,13 @@ exports.optionalDevice = {
alias: 'd'
};
exports.optionalDeviceApiKey = {
signature: 'deviceApiKey',
description: 'custom device key - note that this is only supported on ResinOS 2.0.3+',
parameter: 'device-api-key',
alias: 'k'
};
exports.booleanDevice = {
signature: 'device',
description: 'device',

View File

@ -196,12 +196,7 @@ exports.generate = {
description: 'generate a config.json file',
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',
description: 'custom device key - note that this is only supported on ResinOS 2.0.3+',
parameter: 'device-api-key',
alias: 'k'
}, {
commandOptions.optionalApplication, commandOptions.optionalDevice, commandOptions.optionalDeviceApiKey, {
signature: 'output',
description: 'output',
parameter: 'output',

View File

@ -92,12 +92,7 @@ exports.register = {
description: 'custom uuid',
parameter: 'uuid',
alias: 'u'
}, {
signature: 'deviceApiKey',
description: 'custom device key',
parameter: 'device-api-key',
alias: 'k'
}
}, commandOptions.optionalDeviceApiKey
],
action: function(params, options, done) {
var Promise, ref, ref1, resin;

View File

@ -165,7 +165,7 @@ buildConfig = function(image, deviceType, advanced) {
exports.buildConfig = {
signature: 'os build-config <image> <device-type>',
description: 'build the OS config and save it to the JSON file',
help: 'Use this command to prebuild the OS config once and skip the interactive part of `resin os configure`.\n\nExamples:\n\n $ resin os build-config ../path/rpi3.img raspberrypi3 --output rpi3-config.json\n $ resin os configure ../path/rpi3.img 7cf02a6 --config "$(cat rpi3-config.json)"',
help: 'Use this command to prebuild the OS config once and skip the interactive part of `resin os configure`.\n\nExample:\n\n $ resin os build-config ../path/rpi3.img raspberrypi3 --output rpi3-config.json\n $ resin os configure ../path/rpi3.img 7cf02a6 --config "$(cat rpi3-config.json)"',
permission: 'user',
options: [
commandOptions.advancedConfig, {
@ -188,36 +188,46 @@ exports.buildConfig = {
};
exports.configure = {
signature: 'os configure <image> <uuid> [deviceApiKey]',
signature: 'os configure <image> [uuid] [deviceApiKey]',
description: 'configure an os image',
help: 'Use this command to configure a previously downloaded operating system image for the specific device.\n\nNote that device api keys are only supported on ResinOS 2.0.3+\n\nExamples:\n\n $ resin os configure ../path/rpi.img 7cf02a6\n $ resin os configure ../path/rpi.img 7cf02a6 <existingDeviceKey>',
help: 'Use this command to configure a previously downloaded operating system image for\nthe specific device or for an application generally.\n\nNote that device api keys are only supported on ResinOS 2.0.3+.\n\nThis comand still supports the *deprecated* format where the UUID and optionally device key\nare passed directly on the command line, but the recommended way is to pass either an --app or\n--device argument. The deprecated format will be remove in a future release.\n\nExamples:\n\n $ resin os configure ../path/rpi.img --device 7cf02a6\n $ resin os configure ../path/rpi.img --device 7cf02a6 --deviceApiKey <existingDeviceKey>\n $ resin os configure ../path/rpi.img --app MyApp',
permission: 'user',
options: [
commandOptions.advancedConfig, {
commandOptions.advancedConfig, commandOptions.optionalApplication, commandOptions.optionalDevice, commandOptions.optionalDeviceApiKey, {
signature: 'config',
description: 'path to the config JSON file, see `resin os build-config`',
parameter: 'config'
}
],
action: function(params, options, done) {
var Promise, fs, generateDeviceConfig, helpers, init, readFileAsync, resin;
var Promise, configurationResourceType, deviceApiKey, fs, generateApplicationConfig, generateDeviceConfig, helpers, init, patterns, readFileAsync, ref, resin, uuid;
fs = require('fs');
Promise = require('bluebird');
readFileAsync = Promise.promisify(fs.readFile);
resin = require('resin-sdk-preconfigured');
init = require('resin-device-init');
helpers = require('../utils/helpers');
generateDeviceConfig = require('../utils/config').generateDeviceConfig;
patterns = require('../utils/patterns');
ref = require('../utils/config'), generateDeviceConfig = ref.generateDeviceConfig, generateApplicationConfig = ref.generateApplicationConfig;
if (_.filter([options.device, options.application, params.uuid]).length !== 1) {
patterns.expectedError('To configure an image, you must provide exactly one of:\n\n* A device, with --device <uuid>\n* An application, with --app <appname>\n* [Deprecated] A device, passing its uuid directly on the command line\n\nSee the help page for examples:\n\n $ resin help os configure');
}
if (params.uuid) {
console.warn('Directly passing a UUID to `resin os configure` is deprecated. Pass it with --uuid <uuid> instead.' + (params.deviceApiKey ? ' Device api keys can be passed with --deviceApiKey.\n' : '\n'));
}
uuid = options.device || params.uuid;
deviceApiKey = options.deviceApiKey || params.deviceApiKey;
console.info('Configuring operating system image');
return resin.models.device.get(params.uuid).then(function(device) {
configurationResourceType = uuid ? 'device' : 'application';
return resin.models[configurationResourceType].get(uuid || options.application).then(function(appOrDevice) {
return Promise["try"](function() {
if (options.config) {
return readFileAsync(options.config, 'utf8').then(JSON.parse);
}
return buildConfig(params.image, device.device_type, options.advanced);
return buildConfig(params.image, appOrDevice.device_type, options.advanced);
}).then(function(answers) {
return generateDeviceConfig(device, params.deviceApiKey, answers).then(function(config) {
return init.configure(params.image, device.device_type, config, answers);
return (configurationResourceType === 'device' ? generateDeviceConfig(appOrDevice, deviceApiKey, answers) : generateApplicationConfig(appOrDevice, answers)).then(function(config) {
return init.configure(params.image, appOrDevice.device_type, config, answers);
});
});
}).then(helpers.osProgressHandler).nodeify(done);

View File

@ -224,6 +224,6 @@ exports.expectedError = function(message) {
if (message instanceof Error) {
message = message.message;
}
console.error(chalk.red(message));
exports.printErrorMessage(message);
return process.exit(1);
};

View File

@ -106,7 +106,7 @@ environment variable (in the same standard URL format).
- [os versions &#60;type&#62;](#os-versions-60-type-62-)
- [os download &#60;type&#62;](#os-download-60-type-62-)
- [os build-config &#60;image&#62; &#60;device-type&#62;](#os-build-config-60-image-62-60-device-type-62-)
- [os configure &#60;image&#62; &#60;uuid&#62; [deviceApiKey]](#os-configure-60-image-62-60-uuid-62-deviceapikey-)
- [os configure &#60;image&#62; [uuid] [deviceApiKey]](#os-configure-60-image-62-uuid-deviceapikey-)
- [os initialize &#60;image&#62;](#os-initialize-60-image-62-)
- Config
@ -350,7 +350,7 @@ custom uuid
#### --deviceApiKey, -k &#60;device-api-key&#62;
custom device key
custom device key - note that this is only supported on ResinOS 2.0.3+
## device rm &#60;uuid&#62;
@ -894,7 +894,7 @@ or 'menu' (will show the interactive menu)
Use this command to prebuild the OS config once and skip the interactive part of `resin os configure`.
Examples:
Example:
$ resin os build-config ../path/rpi3.img raspberrypi3 --output rpi3-config.json
$ resin os configure ../path/rpi3.img 7cf02a6 --config "$(cat rpi3-config.json)"
@ -909,16 +909,22 @@ show advanced configuration options
the path to the output JSON file
## os configure &#60;image&#62; &#60;uuid&#62; [deviceApiKey]
## os configure &#60;image&#62; [uuid] [deviceApiKey]
Use this command to configure a previously downloaded operating system image for the specific device.
Use this command to configure a previously downloaded operating system image for
the specific device or for an application generally.
Note that device api keys are only supported on ResinOS 2.0.3+
Note that device api keys are only supported on ResinOS 2.0.3+.
This comand still supports the *deprecated* format where the UUID and optionally device key
are passed directly on the command line, but the recommended way is to pass either an --app or
--device argument. The deprecated format will be remove in a future release.
Examples:
$ resin os configure ../path/rpi.img 7cf02a6
$ resin os configure ../path/rpi.img 7cf02a6 <existingDeviceKey>
$ resin os configure ../path/rpi.img --device 7cf02a6
$ resin os configure ../path/rpi.img --device 7cf02a6 --deviceApiKey <existingDeviceKey>
$ resin os configure ../path/rpi.img --app MyApp
### Options
@ -926,6 +932,18 @@ Examples:
show advanced configuration options
#### --application, --a,app, --a,app &#60;application&#62;
application name
#### --device, -d &#60;device&#62;
device uuid
#### --deviceApiKey, -k &#60;device-api-key&#62;
custom device key - note that this is only supported on ResinOS 2.0.3+
#### --config &#60;config&#62;
path to the config JSON file, see `resin os build-config`

View File

@ -38,6 +38,12 @@ exports.optionalDevice =
description: 'device uuid'
alias: 'd'
exports.optionalDeviceApiKey =
signature: 'deviceApiKey'
description: 'custom device key - note that this is only supported on ResinOS 2.0.3+'
parameter: 'device-api-key'
alias: 'k'
exports.booleanDevice =
signature: 'device'
description: 'device'

View File

@ -237,12 +237,7 @@ exports.generate =
options: [
commandOptions.optionalApplication
commandOptions.optionalDevice
{
signature: 'deviceApiKey'
description: 'custom device key - note that this is only supported on ResinOS 2.0.3+'
parameter: 'device-api-key'
alias: 'k'
}
commandOptions.optionalDeviceApiKey
{
signature: 'output'
description: 'output'

View File

@ -147,12 +147,7 @@ exports.register =
parameter: 'uuid'
alias: 'u'
}
{
signature: 'deviceApiKey'
description: 'custom device key'
parameter: 'device-api-key'
alias: 'k'
}
commandOptions.optionalDeviceApiKey
]
action: (params, options, done) ->
Promise = require('bluebird')

View File

@ -169,7 +169,7 @@ exports.buildConfig =
help: '''
Use this command to prebuild the OS config once and skip the interactive part of `resin os configure`.
Examples:
Example:
$ resin os build-config ../path/rpi3.img raspberrypi3 --output rpi3-config.json
$ resin os configure ../path/rpi3.img 7cf02a6 --config "$(cat rpi3-config.json)"
@ -196,21 +196,30 @@ exports.buildConfig =
.nodeify(done)
exports.configure =
signature: 'os configure <image> <uuid> [deviceApiKey]'
signature: 'os configure <image> [uuid] [deviceApiKey]'
description: 'configure an os image'
help: '''
Use this command to configure a previously downloaded operating system image for the specific device.
Use this command to configure a previously downloaded operating system image for
the specific device or for an application generally.
Note that device api keys are only supported on ResinOS 2.0.3+
Note that device api keys are only supported on ResinOS 2.0.3+.
This comand still supports the *deprecated* format where the UUID and optionally device key
are passed directly on the command line, but the recommended way is to pass either an --app or
--device argument. The deprecated format will be remove in a future release.
Examples:
$ resin os configure ../path/rpi.img 7cf02a6
$ resin os configure ../path/rpi.img 7cf02a6 <existingDeviceKey>
$ resin os configure ../path/rpi.img --device 7cf02a6
$ resin os configure ../path/rpi.img --device 7cf02a6 --deviceApiKey <existingDeviceKey>
$ resin os configure ../path/rpi.img --app MyApp
'''
permission: 'user'
options: [
commandOptions.advancedConfig
commandOptions.optionalApplication
commandOptions.optionalDevice
commandOptions.optionalDeviceApiKey
{
signature: 'config'
description: 'path to the config JSON file, see `resin os build-config`'
@ -224,20 +233,54 @@ exports.configure =
resin = require('resin-sdk-preconfigured')
init = require('resin-device-init')
helpers = require('../utils/helpers')
{ generateDeviceConfig } = require('../utils/config')
patterns = require('../utils/patterns')
{ generateDeviceConfig, generateApplicationConfig } = require('../utils/config')
if _.filter([
options.device
options.application
params.uuid
]).length != 1
patterns.expectedError '''
To configure an image, you must provide exactly one of:
* A device, with --device <uuid>
* An application, with --app <appname>
* [Deprecated] A device, passing its uuid directly on the command line
See the help page for examples:
$ resin help os configure
'''
if params.uuid
console.warn(
'Directly passing a UUID to `resin os configure` is deprecated. Pass it with --uuid <uuid> instead.' +
if params.deviceApiKey
' Device api keys can be passed with --deviceApiKey.\n'
else '\n'
)
uuid = options.device || params.uuid
deviceApiKey = options.deviceApiKey || params.deviceApiKey
console.info('Configuring operating system image')
resin.models.device.get(params.uuid)
.then (device) ->
configurationResourceType = if uuid then 'device' else 'application'
resin.models[configurationResourceType].get(uuid || options.application)
.then (appOrDevice) ->
Promise.try ->
if options.config
return readFileAsync(options.config, 'utf8')
.then(JSON.parse)
return buildConfig(params.image, device.device_type, options.advanced)
return buildConfig(params.image, appOrDevice.device_type, options.advanced)
.then (answers) ->
generateDeviceConfig(device, params.deviceApiKey, answers)
.then (config) ->
init.configure(params.image, device.device_type, config, answers)
(if configurationResourceType == 'device'
generateDeviceConfig(appOrDevice, deviceApiKey, answers)
else
generateApplicationConfig(appOrDevice, answers)
).then (config) ->
init.configure(params.image, appOrDevice.device_type, config, answers)
.then(helpers.osProgressHandler)
.nodeify(done)

View File

@ -177,5 +177,5 @@ exports.printErrorMessage = (message) ->
exports.expectedError = (message) ->
if message instanceof Error
message = message.message
console.error(chalk.red(message))
exports.printErrorMessage(message)
process.exit(1)

View File

@ -1,6 +1,6 @@
{
"name": "resin-cli",
"version": "6.9.0",
"version": "6.10.0",
"description": "The official resin.io CLI tool",
"main": "./build/actions/index.js",
"homepage": "https://github.com/resin-io/resin-cli",