import{n as e}from"./chunk-74CEPOFO-V0JXh91S.mjs";function t(t,n){let r=10,i=null,a=!1,o=!1,s=!1,c=[];for(let l=0;l<t.length;l++){let u=t[l];if(u===`-n`&&l+1<t.length){let e=t[++l];n===`tail`&&e.startsWith(`+`)?(s=!0,r=parseInt(e.slice(1),10)):r=parseInt(e,10)}else if(n===`tail`&&u.startsWith(`-n+`))s=!0,r=parseInt(u.slice(3),10);else if(u.startsWith(`-n`))r=parseInt(u.slice(2),10);else if(u===`-c`&&l+1<t.length)i=parseInt(t[++l],10);else if(u.startsWith(`-c`))i=parseInt(u.slice(2),10);else if(u.startsWith(`--bytes=`))i=parseInt(u.slice(8),10);else if(u.startsWith(`--lines=`))r=parseInt(u.slice(8),10);else if(u===`-q`||u===`--quiet`||u===`--silent`)a=!0;else if(u===`-v`||u===`--verbose`)o=!0;else if(u.match(/^-\d+$/))r=parseInt(u.slice(1),10);else{if(u.startsWith(`--`)||u.startsWith(`-`)&&u!==`-`)return{ok:!1,error:e(n,u)};c.push(u)}}return i!==null&&(Number.isNaN(i)||i<0)?{ok:!1,error:{stdout:``,stderr:`${n}: invalid number of bytes
`,exitCode:1}}:Number.isNaN(r)||r<0?{ok:!1,error:{stdout:``,stderr:`${n}: invalid number of lines
`,exitCode:1}}:{ok:!0,options:{lines:r,bytes:i,quiet:a,verbose:o,files:c,fromLine:s}}}async function n(e,t,n,r){let{quiet:i,verbose:a,files:o}=t;if(o.length===0)return{stdout:r(e.stdin),stderr:``,exitCode:0};let s=``,c=``,l=0,u=a||!i&&o.length>1,d=0;for(let t=0;t<o.length;t++){let i=o[t];try{let t=e.fs.resolvePath(e.cwd,i),n=await e.fs.readFile(t);u&&(d>0&&(s+=`
`),s+=`==> ${i} <==
`),s+=r(n),d++}catch{c+=`${n}: ${i}: No such file or directory
`,l=1}}return{stdout:s,stderr:c,exitCode:l}}function r(e,t,n){if(n!==null)return e.slice(0,n);if(t===0)return``;let r=0,i=0,a=e.length;for(;r<a&&i<t;){let t=e.indexOf(`
`,r);if(t===-1)return`${e}
`;i++,r=t+1}return r>0?e.slice(0,r):``}function i(e,t,n,r){if(n!==null)return e.slice(-n);let i=e.length;if(i===0)return``;if(r){let n=0,r=1;for(;n<i&&r<t;){let t=e.indexOf(`
`,n);if(t===-1)break;r++,n=t+1}let a=e.slice(n);return a.endsWith(`
`)?a:`${a}
`}if(t===0)return``;let a=i-1;e[a]===`
`&&a--;let o=0;for(;a>=0&&o<t;){if(e[a]===`
`&&(o++,o===t)){a++;break}a--}a<0&&(a=0);let s=e.slice(a);return e[i-1]===`
`?s:`${s}
`}export{i,t as n,n as r,r as t};
//# sourceMappingURL=chunk-HDQ56CKY-DZc2LbWr.mjs.map