diff --git a/src/handler/utils/preprocessors/args.ts b/src/handler/utils/preprocessors/args.ts index 6640f92..f5c758e 100644 --- a/src/handler/utils/preprocessors/args.ts +++ b/src/handler/utils/preprocessors/args.ts @@ -30,13 +30,9 @@ export namespace Utils { regexes : {yesRegex: RegExp, noRegex: RegExp} = {yesRegex : /(yes|y|👍)/gi, noRegex : /(no|n|👎)/gi} ): ArgType { - if(arg.match(regexes.yesRegex)) { - return Ok(true); - } - if(arg.match(regexes.noRegex)) { - return Ok(false) - } - return Err(onFailure) + if(arg.match(regexes.yesRegex)) return Ok(true); + if(arg.match(regexes.noRegex)) return Ok(false); + return Err(onFailure); } /** * @@ -48,6 +44,10 @@ export namespace Utils { return Ok(arg.split(sep)); } + export function toPositiveInt(arg: string, onFailure: possibleOutput) : ArgType { + return Utils.parseInt(arg, onFailure).andThen( num => Ok(num > 0 ? num : Math.abs(num))) + } + }