import{n as e}from"./chunk-74CEPOFO-V0JXh91S.mjs";function t(t,n,r){let i=new Map,a=new Map;for(let[e,t]of Object.entries(r)){let n={name:e,type:t.type};t.short&&i.set(t.short,n),t.long&&a.set(t.long,n)}let o=Object.create(null);for(let[e,t]of Object.entries(r))t.default===void 0?t.type===`boolean`&&(o[e]=!1):o[e]=t.default;let s=[],c=!1;for(let r=0;r<n.length;r++){let l=n[r];if(c||!l.startsWith(`-`)||l===`-`){s.push(l);continue}if(l===`--`){c=!0;continue}if(l.startsWith(`--`)){let i=l.indexOf(`=`),s,c;i===-1?s=l.slice(2):(s=l.slice(2,i),c=l.slice(i+1));let u=a.get(s);if(!u)return{ok:!1,error:e(t,l)};let{name:d,type:f}=u;if(f===`boolean`)o[d]=!0;else{if(c===void 0){if(r+1>=n.length)return{ok:!1,error:{stdout:``,stderr:`${t}: option '--${s}' requires an argument
`,exitCode:1}};c=n[++r]}o[d]=f===`number`?parseInt(c,10):c}}else{let a=l.slice(1);for(let s=0;s<a.length;s++){let c=a[s],l=i.get(c);if(!l)return{ok:!1,error:e(t,`-${c}`)};let{name:u,type:d}=l;if(d===`boolean`)o[u]=!0;else{let e;if(s+1<a.length)e=a.slice(s+1);else if(r+1<n.length)e=n[++r];else return{ok:!1,error:{stdout:``,stderr:`${t}: option requires an argument -- '${c}'
`,exitCode:1}};o[u]=d===`number`?parseInt(e,10):e;break}}}}return{ok:!0,result:{flags:o,positional:s}}}export{t};
//# sourceMappingURL=chunk-HWKDQ44K-BJxdK4fT.mjs.map