Merge pull request #320 from resin-io/feat/config-generate

Implement config generate command
This commit is contained in:
Juan Cruz Viotti 2016-02-29 08:40:15 -04:00
commit 797122ce37
6 changed files with 94 additions and 0 deletions

View File

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

View File

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

View File

@ -81,6 +81,7 @@ Now you have access to all the commands referenced below.
- [config read](#config-read)
- [config write &#60;key&#62; &#60;value&#62;](#config-write-60-key-62-60-value-62-)
- [config reconfigure](#config-reconfigure)
- [config generate &#60;uuid&#62;](#config-generate-60-uuid-62-)
- Settings
@ -699,6 +700,21 @@ drive
show advanced commands
## config generate &#60;uuid&#62;
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 &#60;output&#62;
output
# Settings
## settings

View File

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

View File

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

View File

@ -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",