mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-01-30 08:03:55 +00:00
Merge pull request #320 from resin-io/feat/config-generate
Implement config generate command
This commit is contained in:
commit
797122ce37
@ -149,4 +149,37 @@ limitations under the License.
|
||||
}
|
||||
};
|
||||
|
||||
exports.generate = {
|
||||
signature: 'config generate <uuid>',
|
||||
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',
|
||||
options: [
|
||||
{
|
||||
signature: 'output',
|
||||
description: 'output',
|
||||
parameter: 'output',
|
||||
alias: 'o'
|
||||
}
|
||||
],
|
||||
permission: 'user',
|
||||
action: function(params, options, done) {
|
||||
var Promise, _, deviceConfig, form, fs, prettyjson, resin;
|
||||
Promise = require('bluebird');
|
||||
fs = Promise.promisifyAll(require('fs'));
|
||||
resin = require('resin-sdk');
|
||||
_ = require('lodash');
|
||||
form = require('resin-cli-form');
|
||||
deviceConfig = require('resin-device-config');
|
||||
prettyjson = require('prettyjson');
|
||||
return resin.models.device.get(params.uuid).then(function(device) {
|
||||
return resin.models.device.getManifestBySlug(device.device_type).get('options').then(form.run).then(_.partial(deviceConfig.get, device.uuid));
|
||||
}).then(function(config) {
|
||||
if (options.output != null) {
|
||||
return fs.writeFileAsync(options.output, JSON.stringify(config));
|
||||
}
|
||||
return console.log(prettyjson.render(config));
|
||||
}).nodeify(done);
|
||||
}
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
|
@ -123,6 +123,8 @@ limitations under the License.
|
||||
|
||||
capitano.command(actions.config.reconfigure);
|
||||
|
||||
capitano.command(actions.config.generate);
|
||||
|
||||
capitano.command(actions.settings.list);
|
||||
|
||||
capitano.command(actions.logs);
|
||||
|
@ -81,6 +81,7 @@ Now you have access to all the commands referenced below.
|
||||
- [config read](#config-read)
|
||||
- [config write <key> <value>](#config-write-60-key-62-60-value-62-)
|
||||
- [config reconfigure](#config-reconfigure)
|
||||
- [config generate <uuid>](#config-generate-60-uuid-62-)
|
||||
|
||||
- Settings
|
||||
|
||||
@ -699,6 +700,21 @@ drive
|
||||
|
||||
show advanced commands
|
||||
|
||||
## config generate <uuid>
|
||||
|
||||
Use this command to generate a config.json for a device
|
||||
|
||||
Examples:
|
||||
|
||||
$ resin config generate 7cf02a6
|
||||
$ resin config generate 7cf02a6 --output config.json
|
||||
|
||||
### Options
|
||||
|
||||
#### --output, -o <output>
|
||||
|
||||
output
|
||||
|
||||
# Settings
|
||||
|
||||
## settings
|
||||
|
@ -167,3 +167,44 @@ exports.reconfigure =
|
||||
.then ->
|
||||
console.info('Done')
|
||||
.nodeify(done)
|
||||
|
||||
exports.generate =
|
||||
signature: 'config generate <uuid>'
|
||||
description: 'generate a config.json file'
|
||||
help: '''
|
||||
Use this command to generate a config.json for a device
|
||||
|
||||
Examples:
|
||||
|
||||
$ resin config generate 7cf02a6
|
||||
$ resin config generate 7cf02a6 --output config.json
|
||||
'''
|
||||
options: [
|
||||
{
|
||||
signature: 'output'
|
||||
description: 'output'
|
||||
parameter: 'output'
|
||||
alias: 'o'
|
||||
}
|
||||
]
|
||||
permission: 'user'
|
||||
action: (params, options, done) ->
|
||||
Promise = require('bluebird')
|
||||
fs = Promise.promisifyAll(require('fs'))
|
||||
resin = require('resin-sdk')
|
||||
_ = require('lodash')
|
||||
form = require('resin-cli-form')
|
||||
deviceConfig = require('resin-device-config')
|
||||
prettyjson = require('prettyjson')
|
||||
|
||||
resin.models.device.get(params.uuid).then (device) ->
|
||||
resin.models.device.getManifestBySlug(device.device_type)
|
||||
.get('options')
|
||||
.then(form.run)
|
||||
.then(_.partial(deviceConfig.get, device.uuid))
|
||||
.then (config) ->
|
||||
if options.output?
|
||||
return fs.writeFileAsync(options.output, JSON.stringify(config))
|
||||
|
||||
console.log(prettyjson.render(config))
|
||||
.nodeify(done)
|
||||
|
@ -97,6 +97,7 @@ capitano.command(actions.os.initialize)
|
||||
capitano.command(actions.config.read)
|
||||
capitano.command(actions.config.write)
|
||||
capitano.command(actions.config.reconfigure)
|
||||
capitano.command(actions.config.generate)
|
||||
|
||||
# ---------- Settings Module ----------
|
||||
capitano.command(actions.settings.list)
|
||||
|
@ -48,6 +48,7 @@
|
||||
"resin-cli-form": "^1.4.0",
|
||||
"resin-cli-visuals": "^1.2.2",
|
||||
"resin-config-json": "^1.0.0",
|
||||
"resin-device-config": "^2.6.1",
|
||||
"resin-device-init": "^2.0.0",
|
||||
"resin-image-manager": "^4.0.0",
|
||||
"resin-pine": "^1.3.0",
|
||||
|
Loading…
x
Reference in New Issue
Block a user