Merge pull request #234 from resin-io/jviotti/feature/advanced-options

Ignore advanced configuration questions by default
This commit is contained in:
Juan Cruz Viotti 2015-10-20 09:12:38 -04:00
commit ff81c1e514
5 changed files with 60 additions and 2 deletions

View File

@ -91,9 +91,31 @@
description: 'configure an os image',
help: 'Use this command to configure a previously download operating system image with a device.\n\nExamples:\n\n $ resin os configure ../path/rpi.img 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9',
permission: 'user',
options: [
{
signature: 'advanced',
description: 'show advanced commands',
boolean: true,
alias: 'v'
}
],
action: function(params, options, done) {
console.info('Configuring operating system image');
return resin.models.device.get(params.uuid).get('device_type').then(resin.models.device.getManifestBySlug).get('options').then(form.run).then(function(answers) {
return resin.models.device.get(params.uuid).get('device_type').then(resin.models.device.getManifestBySlug).get('options').then(function(questions) {
var advancedGroup, override;
if (!options.advanced) {
advancedGroup = _.findWhere(questions, {
name: 'advanced',
isGroup: true
});
if (advancedGroup != null) {
override = helpers.getGroupDefaults(advancedGroup);
}
}
return form.run(questions, {
override: override
});
}).then(function(answers) {
return init.configure(params.image, params.uuid, answers).then(stepHandler);
}).nodeify(done);
}

View File

@ -15,6 +15,12 @@
chalk = require('chalk');
exports.getGroupDefaults = function(group) {
return _.chain(group).get('options').map(function(question) {
return [question.name, question["default"]];
}).object().value();
};
exports.getOperatingSystem = function() {
var platform;
platform = os.platform();

View File

@ -562,6 +562,12 @@ Examples:
$ resin os configure ../path/rpi.img 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9
### Options
#### --advanced, -v
show advanced commands
## os initialize <image>
Use this command to initialize a previously configured operating system image.

View File

@ -84,13 +84,29 @@ exports.configure =
$ resin os configure ../path/rpi.img 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9
'''
permission: 'user'
options: [
signature: 'advanced'
description: 'show advanced commands'
boolean: true
alias: 'v'
]
action: (params, options, done) ->
console.info('Configuring operating system image')
resin.models.device.get(params.uuid)
.get('device_type')
.then(resin.models.device.getManifestBySlug)
.get('options')
.then(form.run)
.then (questions) ->
if not options.advanced
advancedGroup = _.findWhere questions,
name: 'advanced'
isGroup: true
if advancedGroup?
override = helpers.getGroupDefaults(advancedGroup)
return form.run(questions, { override })
.then (answers) ->
init.configure(params.image, params.uuid, answers).then(stepHandler)
.nodeify(done)

View File

@ -6,6 +6,14 @@ child_process = require('child_process')
os = require('os')
chalk = require('chalk')
exports.getGroupDefaults = (group) ->
return _.chain(group)
.get('options')
.map (question) ->
return [ question.name, question.default ]
.object()
.value()
exports.getOperatingSystem = ->
platform = os.platform()
platform = 'osx' if platform is 'darwin'