Skip to content

Commit

Permalink
feat: add parsing enum by description
Browse files Browse the repository at this point in the history
- Add parsing of enum by description
- Fix enum regexp

Closes #131
  • Loading branch information
ifedchankau committed Aug 13, 2018
1 parent 12941a7 commit b99fd8c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ const getArgumentObject = (object, context) => {
let argument = context.get.template.argument();
object.arg = removeExtraCharacters(object.arg);
argument = {
enum: getEnum(object.arg, context),
enum: getEnum(object.arg + object.description, context),
longName: getPropertyName(object.arg, context.regexp.argument.long),
shortName: getPropertyName(object.arg, context.regexp.argument.short),
defaultValue: getDefaultValue(
object.description, context.regexp.defaultValue),
description: object.description.trim(),
};
argument.isFlag = isDefaultBollean(argument.defaultValue)
&& !isPropertyTyped(object.arg);

argument.isFlag = !isPropertyTyped(object.arg)
&& isFieldBoolean(argument.defaultValue)
&& (argument.enum === null);
return argument;
};

Expand Down Expand Up @@ -68,19 +68,19 @@ const getPropertyName = (string, regexp) => {
};

/**
* Checks default values on bollean
* @param {string} string - default value
* @return {bollean} - result of check
* Checks is given property of argument boolean
* @param {string} string - value of property
* @return {boolean} - result of check
*/
const isDefaultBollean = (string) => {
const isFieldBoolean = (string) => {
return string && !(string === 'true' || string === 'false' ) ? false : true;
};

/**
* Checks if argument string has any types by
* additional chars after property name
* @param {string} string - argument string without description
* @return {bollean} - result of check
* @return {bool} - result of check
*/
const isPropertyTyped = (string) => {
let isType = false;
Expand Down
2 changes: 1 addition & 1 deletion src/template/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const context = {
filePath: 'file|path',
delimiter: '-[^ \t(\n|\r\n)]+(\\s|=)[^ \t(\n|\r\n)-]',
enumValues: {
enum: '<(([\\w]+\\|)+[\\w]+)>',
enum: '<(([\\S]+\\|)+[\\S]+)>',
split: '|',
},
argument: {
Expand Down

0 comments on commit b99fd8c

Please sign in to comment.