import{b as x}from"./chunk-7L36YK2X.js";import"./chunk-NUFRM6SI.js";import{a as y,b as I,c as m}from"./chunk-74CEPOFO.js";import"./chunk-DXB73IDG.js";var W={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 k(t){let c=[],l=t.split(",");for(let n of l)if(n.includes("-")){let[s,r]=n.split("-");c.push({start:s?parseInt(s,10):1,end:r?parseInt(r,10):null})}else{let s=parseInt(n,10);c.push({start:s,end:s})}return c}function C(t,c){let l=[];for(let n of c){let s=n.start-1,r=n.end===null?t.length:n.end;for(let i=s;i<r&&i<t.length;i++)i>=0&&!l.includes(t[i])&&l.push(t[i])}return l}var E={name:"cut",async execute(t,c){if(I(t))return y(W);let l="	",n=null,s=null,r=!1,i=[];for(let o=0;o<t.length;o++){let e=t[o];if(e==="-d")l=t[++o]||"	";else if(e.startsWith("-d"))l=e.slice(2);else if(e==="-f")n=t[++o];else if(e.startsWith("-f"))n=e.slice(2);else if(e==="-c")s=t[++o];else if(e.startsWith("-c"))s=e.slice(2);else if(e==="-s"||e==="--only-delimited")r=!0;else{if(e.startsWith("--"))return m("cut",e);if(e.startsWith("-")){let f=!1;for(let u of e.slice(1))if(u==="s")r=!0;else if(!"dfc".includes(u)){f=!0;break}if(f)return m("cut",e)}else i.push(e)}}if(!n&&!s)return{stdout:"",stderr:`cut: you must specify a list of bytes, characters, or fields
`,exitCode:1};let p=await x(c,i,{cmdName:"cut"});if(!p.ok)return p.error;let a=p.content.split(`
`);a.length>0&&a[a.length-1]===""&&a.pop();let g=k(n||s||"1"),h="";for(let o of a)if(s){let e=o.split(""),f=[];for(let u of g){let w=u.start-1,L=u.end===null?e.length:u.end;for(let d=w;d<L&&d<e.length;d++)d>=0&&f.push(e[d])}h+=`${f.join("")}
`}else{if(r&&!o.includes(l))continue;let e=o.split(l),f=C(e,g);h+=`${f.join(l)}
`}return{stdout:h,stderr:"",exitCode:0}}};export{E as cutCommand};
