Skip to content

Commit

Permalink
fix: result json file consist old arguments
Browse files Browse the repository at this point in the history
Closes #56
  • Loading branch information
ifedchankau authored and itekaf committed Jul 26, 2018
1 parent 1d043a3 commit fee6ca7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
13 changes: 6 additions & 7 deletions src/handle.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ const context = require('./template/context.js');

const handle = (help, config) => {
try {
context.options = [];
Object.keys(context.section).forEach((sectionName) => {
let section = context.section[sectionName];
let sectionTitle = config.section[sectionName].name;
section.data = findSection(sectionTitle, help);
if (section.data.length > 0) {
section.data.forEach((data) =>
section.func(data, context, argumentTemplate));
const data = findSection(sectionTitle, help);
if (data.length > 0) {
data.forEach((object) =>
section.func(object, context, argumentTemplate));
} else if (section.required) {
const sectionNotFound =
new TypeError(`Required section ${sectionName} not found`);
throw sectionNotFound;
throw new Error(`Required section ${sectionName} not found`);
}
});
return context;
Expand Down
3 changes: 0 additions & 3 deletions src/template/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ const parseSection = require('./../parseSection.js');
const context = {
section: {
options: {
data: [],
required: true,
func: parseSection.options,
},
usage: {
data: [],
required: false,
func: parseSection.usage,
},
examples: {
data: [],
required: false,
func: parseSection.examples,
},
Expand Down
9 changes: 5 additions & 4 deletions src/templatizer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict';
const fs = require('fs');
const argumentsTemplate = JSON.parse(fs.readFileSync('./src/template/args.json'));
const optionTemplate = require('./template/option.json');

const templatizer = (context) => {
const argumentsTemplate = require('./template/args.json');
const optionTemplate = require('./template/option.json');

argumentsTemplate.definitions.arguments.properties = {};
let result = argumentsTemplate;
context.options.map((option) => {
let optionSchema = Object.assign({}, optionTemplate);
Expand Down Expand Up @@ -37,7 +38,7 @@ const templatizer = (context) => {
// TODO: argument types
}
optionSchema.description = option.description;
optionSchema.default = option.defaultValues;
optionSchema.default = option.defaultValue;
result.definitions.arguments.properties[argumentName] = optionSchema;
});

Expand Down

0 comments on commit fee6ca7

Please sign in to comment.