mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-04-27 06:20:14 +00:00
Merge pull request #331 from resin-io/feat/config-generate-application
Allow generating a config.json from an application with config generate
This commit is contained in:
commit
d4c44bf350
@ -16,6 +16,10 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
var commandOptions;
|
||||||
|
|
||||||
|
commandOptions = require('./command-options');
|
||||||
|
|
||||||
exports.read = {
|
exports.read = {
|
||||||
signature: 'config read',
|
signature: 'config read',
|
||||||
description: 'read a device configuration',
|
description: 'read a device configuration',
|
||||||
@ -189,11 +193,11 @@ limitations under the License.
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.generate = {
|
exports.generate = {
|
||||||
signature: 'config generate <uuid>',
|
signature: 'config generate',
|
||||||
description: 'generate a config.json file',
|
description: 'generate a config.json file',
|
||||||
help: 'Use this command to generate a config.json for a device\n\nExamples:\n\n $ resin config generate 7cf02a6\n $ resin config generate 7cf02a6 --output config.json',
|
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 --output config.json\n $ resin config generate --app MyApp\n $ resin config generate --app MyApp --output config.json',
|
||||||
options: [
|
options: [
|
||||||
{
|
commandOptions.optionalApplication, commandOptions.optionalDevice, {
|
||||||
signature: 'output',
|
signature: 'output',
|
||||||
description: 'output',
|
description: 'output',
|
||||||
parameter: 'output',
|
parameter: 'output',
|
||||||
@ -210,8 +214,21 @@ limitations under the License.
|
|||||||
form = require('resin-cli-form');
|
form = require('resin-cli-form');
|
||||||
deviceConfig = require('resin-device-config');
|
deviceConfig = require('resin-device-config');
|
||||||
prettyjson = require('prettyjson');
|
prettyjson = require('prettyjson');
|
||||||
return resin.models.device.get(params.uuid).then(function(device) {
|
if ((options.device == null) && (options.application == null)) {
|
||||||
return resin.models.device.getManifestBySlug(device.device_type).get('options').then(form.run).then(_.partial(deviceConfig.getByDevice, device.uuid));
|
throw new Error('You have to pass either a device or an application.\n\nSee the help page for examples:\n\n $ resin help config generate');
|
||||||
|
}
|
||||||
|
return Promise["try"](function() {
|
||||||
|
if (options.device != null) {
|
||||||
|
return resin.models.device.get(options.device);
|
||||||
|
}
|
||||||
|
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) {
|
||||||
|
if (resource.uuid != null) {
|
||||||
|
return deviceConfig.getByDevice(resource.uuid, answers);
|
||||||
|
}
|
||||||
|
return deviceConfig.getByApplication(resource.app_name, answers);
|
||||||
|
});
|
||||||
}).then(function(config) {
|
}).then(function(config) {
|
||||||
if (options.output != null) {
|
if (options.output != null) {
|
||||||
return fs.writeFileAsync(options.output, JSON.stringify(config));
|
return fs.writeFileAsync(options.output, JSON.stringify(config));
|
||||||
|
@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
###
|
###
|
||||||
|
|
||||||
|
commandOptions = require('./command-options')
|
||||||
|
|
||||||
exports.read =
|
exports.read =
|
||||||
signature: 'config read'
|
signature: 'config read'
|
||||||
description: 'read a device configuration'
|
description: 'read a device configuration'
|
||||||
@ -214,17 +216,21 @@ exports.reconfigure =
|
|||||||
.nodeify(done)
|
.nodeify(done)
|
||||||
|
|
||||||
exports.generate =
|
exports.generate =
|
||||||
signature: 'config generate <uuid>'
|
signature: 'config generate'
|
||||||
description: 'generate a config.json file'
|
description: 'generate a config.json file'
|
||||||
help: '''
|
help: '''
|
||||||
Use this command to generate a config.json for a device
|
Use this command to generate a config.json for a device or application
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
$ resin config generate 7cf02a6
|
$ resin config generate --device 7cf02a6
|
||||||
$ resin config generate 7cf02a6 --output config.json
|
$ resin config generate --device 7cf02a6 --output config.json
|
||||||
|
$ resin config generate --app MyApp
|
||||||
|
$ resin config generate --app MyApp --output config.json
|
||||||
'''
|
'''
|
||||||
options: [
|
options: [
|
||||||
|
commandOptions.optionalApplication
|
||||||
|
commandOptions.optionalDevice
|
||||||
{
|
{
|
||||||
signature: 'output'
|
signature: 'output'
|
||||||
description: 'output'
|
description: 'output'
|
||||||
@ -242,11 +248,27 @@ exports.generate =
|
|||||||
deviceConfig = require('resin-device-config')
|
deviceConfig = require('resin-device-config')
|
||||||
prettyjson = require('prettyjson')
|
prettyjson = require('prettyjson')
|
||||||
|
|
||||||
resin.models.device.get(params.uuid).then (device) ->
|
if not options.device? and not options.application?
|
||||||
resin.models.device.getManifestBySlug(device.device_type)
|
throw new Error '''
|
||||||
|
You have to pass either a device or an application.
|
||||||
|
|
||||||
|
See the help page for examples:
|
||||||
|
|
||||||
|
$ resin help config generate
|
||||||
|
'''
|
||||||
|
|
||||||
|
Promise.try ->
|
||||||
|
if options.device?
|
||||||
|
return resin.models.device.get(options.device)
|
||||||
|
return resin.models.application.get(options.application)
|
||||||
|
.then (resource) ->
|
||||||
|
resin.models.device.getManifestBySlug(resource.device_type)
|
||||||
.get('options')
|
.get('options')
|
||||||
.then(form.run)
|
.then(form.run)
|
||||||
.then(_.partial(deviceConfig.getByDevice, device.uuid))
|
.then (answers) ->
|
||||||
|
if resource.uuid?
|
||||||
|
return deviceConfig.getByDevice(resource.uuid, answers)
|
||||||
|
return deviceConfig.getByApplication(resource.app_name, answers)
|
||||||
.then (config) ->
|
.then (config) ->
|
||||||
if options.output?
|
if options.output?
|
||||||
return fs.writeFileAsync(options.output, JSON.stringify(config))
|
return fs.writeFileAsync(options.output, JSON.stringify(config))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user