Skip to content

Commit

Permalink
fix: different sections parsing
Browse files Browse the repository at this point in the history
2 problems fixed:
- different sections wasn't parsed, only first
- section name wasn't passed to the findSection function

Closes #41
  • Loading branch information
ifedchankau authored and itekaf committed Jul 19, 2018
1 parent 8a437f1 commit 3e5e19a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/handle.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ const handle = (help, config) => {
try {
Object.keys(context.section).forEach((sectionName) => {
let section = context.section[sectionName];
section.data = findSection(section.name, help);
let sectionTitle = config.section[sectionName].name;
section.data = findSection(sectionTitle, help);
if (section.data) {
section.data.forEach((data) =>
section.func(data, context, argumentTemplate));
} else if (section.required) {
const sectionNotFound
= new Error(`Required section ${section.name} not found`);
= new Error(`Required section ${sectionTitle} not found`);
throw sectionNotFound;
}
});
Expand All @@ -25,8 +26,8 @@ const handle = (help, config) => {

const findSection = (sectionName, help) => {
try {
const regularExp =
new RegExp(`[^\n]*${sectionName}[^\n]*\n?(?:[ \t].*?(?:\n|$))*`);
const regularExp = new
RegExp(`[^\n]*${sectionName}[^\n]*\n?(?:[ \t].*?(?:\n|$))*`, 'gi');
const matches = help.match(regularExp);
return matches ? matches.map((match) => match.trim()) : [];
} catch (error) {
Expand Down
2 changes: 0 additions & 2 deletions src/parseSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@ const splitSection = (section) => {
result[j - 1] = result[j - 1] + str;
}
});

return result;
} catch (error) {
throw error;
}
};


exports = module.exports = {
options: options,
usage: usage,
Expand Down

0 comments on commit 3e5e19a

Please sign in to comment.