#!/usr/bin/env node
import{b as x}from"./chunk-UT3LGGF3.js";import{a as y,b as I,c as g}from"./chunk-GTNBSMZR.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 F(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 L(t,c){let l=[];for(let n of c){let s=n.start-1,r=n.end===null?t.length:n.end;for(let o=s;o<r&&o<t.length;o++)o>=0&&!l.includes(t[o])&&l.push(t[o])}return l}var k={name:"cut",async execute(t,c){if(I(t))return y(w);let l="	",n=null,s=null,r=!1,o=[];for(let i=0;i<t.length;i++){let e=t[i];if(e==="-d")l=t[++i]||"	";else if(e.startsWith("-d"))l=e.slice(2);else if(e==="-f")n=t[++i];else if(e.startsWith("-f"))n=e.slice(2);else if(e==="-c")s=t[++i];else if(e.startsWith("-c"))s=e.slice(2);else if(e==="-s"||e==="--only-delimited")r=!0;else{if(e.startsWith("--"))return g("cut",e);if(e.startsWith("-")){let a=!1;for(let f of e.slice(1))if(f==="s")r=!0;else if(!"dfc".includes(f)){a=!0;break}if(a)return g("cut",e)}else o.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,o,{cmdName:"cut"});if(!p.ok)return p.error;let u=p.content.split(`
`);u.length>0&&u[u.length-1]===""&&u.pop();let m=F(n||s||"1"),h="";for(let i of u)if(s){let e=i.split(""),a=[];for(let f of m){let v=f.start-1,H=f.end===null?e.length:f.end;for(let d=v;d<H&&d<e.length;d++)d>=0&&a.push(e[d])}h+=`${a.join("")}
`}else{if(r&&!i.includes(l))continue;let e=i.split(l),a=L(e,m);h+=`${a.join(l)}
`}return{stdout:h,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{k as a,C as b};
