Skip to content

Commit

Permalink
feat: add parsing of arguments with "linterhub:" prefix:
Browse files Browse the repository at this point in the history
- add parsing of arguments with prefix "linterhub:"
- add parsing of "Usage" section for "linterhub:path" argument

Closes #11
  • Loading branch information
ifedchankau authored and itekaf committed Jul 16, 2018
1 parent 4853335 commit c7f3d6a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
29 changes: 20 additions & 9 deletions src/handle.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
const argumentTemplate = {
shortName: null,
longName: null,
isFlag: true,
default: false,
description: null
};

const handle = (help) => {
const sectionName = "Options:";
const sectionName = {
options: "Options:",
usage: "Usage:"
};
let options = [];

parseSection(sectionName, help).forEach(section => {
parseSection(sectionName.options, help).forEach(section => {
splitSection(section).forEach(option => {
if (option.indexOf("-") === 0) {
options.push(parseOption(option));
}
});
});

parseSection(sectionName.usage, help).forEach(section => {
let argument = Object.assign({}, argumentTemplate);
argument.longName = "";
section.match(/file|path/i) ? options.push(argument) : "";
});
return options;
};

Expand Down Expand Up @@ -40,13 +57,7 @@ const splitSection = (section) => {
};

const parseOption = (option) => {
let argument = {
shortName: null,
longName: null,
isFlag: true,
defaultValue: false,
description: null
};
let argument = Object.assign({}, argumentTemplate);

option.trim().split(/\s\s+/, 2).map((section, index) => {
index === 0 ? setArgument(section, argument) : setDescription(section, argument);
Expand Down
2 changes: 1 addition & 1 deletion src/template/option.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "",
"type": "",
"type": "string",
"description": "",
"default": ""
}
28 changes: 24 additions & 4 deletions src/templatizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,34 @@ const templatizer = (options) => {
let optionSchema = Object.assign({}, optionTemplate);
const argumentName = option.longName;
switch (argumentName){
//TODO: arguments with prefix linterhub:
case "--version":
optionSchema.id = "linterhub:version";
optionSchema.type = "null";
break;
case "--help":
optionSchema.id = "linterhub:help";
optionSchema.type = "null";
break;
case "--config":
optionSchema.id = "linterhub:config";
break;
case "--stdin":
optionSchema.id = "linterhub:stdin";
break;
case "--stdin-filename":
case "--stdin-filepath":
optionSchema.id = "linterhub:filename";
break;
case "":
optionSchema.id = "linterhub:path";
optionSchema.description = "Path to file or folder to analyze";
break;
default:
optionSchema.id = (!option.isFlag ? "args:" : "") + option.longName;
//TODO: argument types
optionSchema.type = "string";
optionSchema.description = option.description;
optionSchema.default = option.defaultValue;
}
optionSchema.description = option.description;
optionSchema.default = option.default;
result.definitions.arguments.properties[argumentName] = optionSchema;
});

Expand Down

0 comments on commit c7f3d6a

Please sign in to comment.