UNPKG

@mornya/cli-libs

Version:
1 lines 2 kB
"use strict";var d=this&&this.__read||function(e,r){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var n,o,i=t.call(e),l=[];try{for(;(void 0===r||0<r--)&&!(n=i.next()).done;)l.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(t=i.return)&&t.call(i)}finally{if(o)throw o.error}}return l},v=this&&this.__values||function(e){var r="function"==typeof Symbol&&Symbol.iterator,t=r&&e[r],n=0;if(t)return t.call(e);if(e&&"number"==typeof e.length)return{next:function(){return{value:(e=e&&n>=e.length?void 0:e)&&e[n++],done:!e}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")};function parse(){return process.argv.slice(2).filter(Boolean)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.getArguments=exports.hasAll=exports.has=exports.parse=void 0,exports.parse=parse,exports.has=function has(r){var t,e=parse();return!(!e.length||!r)&&("string"==typeof r?-1!==e.findIndex(function(e){return e===r.trim()}):(t=new RegExp(r.test),-1!==e.findIndex(function(e){return t.test(e)})))},exports.hasAll=function hasAll(e){var l=parse();return l.length&&e.length?e.reduce(function(e,r){var t,n,o,i;return"string"==typeof r?i=l.findIndex(function(e){return r===e.split("=")[0]}):(t=new RegExp(r.test),i=l.findIndex(function(e){return t.test(e.split("=")[0])}),n=null==r?void 0:r.key),-1!==i&&(o=(i=d(l[i].split("="),2))[0],i=i[1],e[null!=n?n:o]=null!=(n=null==i?void 0:i.replace(/^["'`]?(.+?)["'`]?$/,"$1"))?n:"true"),e},{}):{}},exports.getArguments=function getArguments(e){var r,t,n,o=parse(),i=null!=(n=null==(n=o[0])?void 0:n.trim())?n:"",l="",a=!1;try{for(var s=v(Object.entries(e)),u=s.next();!u.done;u=s.next()){var f=d(u.value,2),c=f[0],p=f[1];if(i===p.action||i===p.alias){l=c,a=i===p.alias;break}}}catch(e){r={error:e}}finally{try{u&&!u.done&&(t=s.return)&&t.call(s)}finally{if(r)throw r.error}}return{args:null!=(n=o.slice(1))?n:[],action:l,isAliased:a,isUnknown:!l,availCommands:Object.entries(e).map(function(e){return e[1]})}};