UNPKG

1.14 kBJavaScriptView Raw
1"use strict";const e=require("lodash");var n={help:{help:"print help info",isflag:!0},debug:{help:"print debug info of API calls",isflag:!0}},r=function(n){DEBUG&&(Console.debug("Processging additional parameters"),Console.debug(n));var r=[],o={};return n.forEach(function(n){if(n.startsWith("--")){var i=n.split("=",1)[0].replace("--",""),s=n.split("=")[1];e.isEmpty(s)&&(s=!0),o[i]=s}else n.startsWith("-")&&2===n.length?o[n[1]]=!0:r.push(n)}),[r,o]},o=function(n,r,o){var i=n.argSpecs||[],s=n.argOptionSpecs||{},t=[];return i.forEach(function(e,n){var o=r[n];!o&&e.required&&t.push("Missing required parameter for command at position "+(n+1)+"/"+e.parameter),o&&e.enum&&e.enum.length&&-1==e.enum.indexOf(o)&&t.push("Invalid argument for a command should be one of the",e.enum)}),e.forEach(s,function(e,n){var r=o[n];e.required&&!r&&t.push("Missing required command options -- "+n),r&&e.enum&&e.enum.length&&-1===e.enum.indexOf(r)&&t.push("Unexpected options for -- "+n+" must be one of "+e.enum)}),e.forEach(o,function(e,n){s[n]||t.push("Invalid command option -- "+n)}),t};module.exports={parseArgs:r,checkArgs:o,globalArgOptionsSpec:n};
\No newline at end of file