import{n as e,r as t,t as n}from"./chunk-74CEPOFO-V0JXh91S.mjs";import{t as r}from"./chunk-7L36YK2X-B3QRwLbB.mjs";var i={name:`cut`,summary:`remove sections from each line of files`,usage:`cut [OPTION]... [FILE]...`,options:[`-c LIST              select only these characters`,`-d DELIM             use DELIM instead of TAB for field delimiter`,`-f LIST              select only these fields`,`-s, --only-delimited  do not print lines without delimiters`,`    --help           display this help and exit`]};function a(e){let t=[],n=e.split(`,`);for(let e of n)if(e.includes(`-`)){let[n,r]=e.split(`-`);t.push({start:n?parseInt(n,10):1,end:r?parseInt(r,10):null})}else{let n=parseInt(e,10);t.push({start:n,end:n})}return t}function o(e,t){let n=[];for(let r of t){let t=r.start-1,i=r.end===null?e.length:r.end;for(let r=t;r<i&&r<e.length;r++)r>=0&&!n.includes(e[r])&&n.push(e[r])}return n}var s={name:`cut`,async execute(s,c){if(n(s))return t(i);let l=`	`,u=null,d=null,f=!1,p=[];for(let t=0;t<s.length;t++){let n=s[t];if(n===`-d`)l=s[++t]||`	`;else if(n.startsWith(`-d`))l=n.slice(2);else if(n===`-f`)u=s[++t];else if(n.startsWith(`-f`))u=n.slice(2);else if(n===`-c`)d=s[++t];else if(n.startsWith(`-c`))d=n.slice(2);else if(n===`-s`||n===`--only-delimited`)f=!0;else{if(n.startsWith(`--`))return e(`cut`,n);if(n.startsWith(`-`)){let t=!1;for(let e of n.slice(1))if(e===`s`)f=!0;else if(!`dfc`.includes(e)){t=!0;break}if(t)return e(`cut`,n)}else p.push(n)}}if(!u&&!d)return{stdout:``,stderr:`cut: you must specify a list of bytes, characters, or fields
`,exitCode:1};let m=await r(c,p,{cmdName:`cut`});if(!m.ok)return m.error;let h=m.content.split(`
`);h.length>0&&h[h.length-1]===``&&h.pop();let g=a(u||d||`1`),_=``;for(let e of h)if(d){let t=e.split(``),n=[];for(let e of g){let r=e.start-1,i=e.end===null?t.length:e.end;for(let e=r;e<i&&e<t.length;e++)e>=0&&n.push(t[e])}_+=`${n.join(``)}
`}else{if(f&&!e.includes(l))continue;let t=o(e.split(l),g);_+=`${t.join(l)}
`}return{stdout:_,stderr:``,exitCode:0,stdoutEncoding:`binary`}}},c={name:`cut`,flags:[{flag:`-d`,type:`value`,valueHint:`delimiter`},{flag:`-f`,type:`value`,valueHint:`string`},{flag:`-c`,type:`value`,valueHint:`string`},{flag:`-s`,type:`boolean`}],stdinType:`text`,needsFiles:!0};export{s as n,c as t};
//# sourceMappingURL=chunk-SDNKECQQ-BsAYzqU5.mjs.map