Skip to content
This repository has been archived by the owner on Feb 26, 2020. It is now read-only.

Commit

Permalink
Update config (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
axelchalon authored Aug 6, 2018
1 parent ab8529b commit 381a584
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 200 deletions.
16 changes: 13 additions & 3 deletions scripts/generate-config-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ function getCliOptions (source) {

const cliOptions = [];
for (const [, type, variableName, defaultValueString, configCallbackString, helpString] of execAll(regex, source)) {
if (configCallbackString.includes('_legacy')) {
continue;
}
cliOptions.push({type, variableName, defaultValueString, configCallbackString, helpString});
}

Expand Down Expand Up @@ -63,9 +66,16 @@ function parseDefaultValue (defaultValue) {
return [];
default:
try {
// Remove thousands separators if numeric value
if (/^\d[\d_]+\d$/.test(defaultValue)) {
defaultValue = defaultValue.replace(/_/g, '');
}

defaultValue = defaultValue.replace(/^Some\((".+").into\(\)\)$/, '$1');

return JSON.parse(defaultValue);
} catch (e) {
console.warn('Warning: Failed to parse default value', defaultValue);
console.warn('Warning: Failed to parse default value', defaultValue, e.message);
}
}
}
Expand Down Expand Up @@ -117,7 +127,7 @@ function makeCliConfigTree (parsedCliOptions) {
function getStructFields (name, source) {
const subsource = source.match(new RegExp(`^struct ${name} {[^]+?}`, 'm'))[0];

const fields = subsource.split('\n').slice(1, -1);
const fields = subsource.split('\n').slice(1, -1).filter(s => s.trim() && !s.trim().startsWith('#') && !s.trim().startsWith('_legacy'));

const parsedFields = fields.map(line => {
const matches = line.match(/^\s*(\w+): Option<([\w<>]+)>,$/);
Expand Down Expand Up @@ -245,7 +255,7 @@ function augment (data, extra) {
return prop;
})
})
);
).filter(({props}) => props.length);

// Hydrate config structs with CLI options

Expand Down
Loading

0 comments on commit 381a584

Please sign in to comment.