#!/usr/bin/env node
import{a as S}from"./chunk-UT3LGGF3.js";import{a as b}from"./chunk-JBABAK44.js";import{a as x,b as y}from"./chunk-GTNBSMZR.js";var $={name:"wc",summary:"print newline, word, and byte counts for each file",usage:"wc [OPTION]... [FILE]...",options:["-c, --bytes      print the byte counts","-m, --chars      print the character counts","-l, --lines      print the newline counts","-w, --words      print the word counts","    --help       display this help and exit"]},H={lines:{short:"l",long:"lines",type:"boolean"},words:{short:"w",long:"words",type:"boolean"},bytes:{short:"c",long:"bytes",type:"boolean"},chars:{short:"m",long:"chars",type:"boolean"}},E={name:"wc",async execute(a,c){if(y(a))return x($);let n=b("wc",a,H);if(!n.ok)return n.error;let{lines:o,words:e}=n.result.flags,s=n.result.flags.bytes||n.result.flags.chars,t=n.result.positional;!o&&!e&&!s&&(o=e=s=!0);let i=await S(c,t,{cmdName:"wc",stopOnError:!1});if(t.length===0){let r=C(i.files[0].content);return{stdout:`${w(r,o,e,s,"",0)}
`,stderr:"",exitCode:0}}let h=[],p=0,d=0,u=0;for(let{filename:r,content:m}of i.files){let f=C(m);p+=f.lines,d+=f.words,u+=f.chars,h.push({filename:r,stats:f})}let F=t.length>1?p:Math.max(...h.map(r=>r.stats.lines)),M=t.length>1?d:Math.max(...h.map(r=>r.stats.words)),L=t.length>1?u:Math.max(...h.map(r=>r.stats.chars)),l=t.length>1?3:0;o&&(l=Math.max(l,String(F).length)),e&&(l=Math.max(l,String(M).length)),s&&(l=Math.max(l,String(L).length));let g="";for(let{filename:r,stats:m}of h)g+=`${w(m,o,e,s,r,l)}
`;return t.length>1&&(g+=`${w({lines:p,words:d,chars:u},o,e,s,"total",l)}
`),{stdout:g,stderr:i.stderr,exitCode:i.exitCode}}};function C(a){let c=a.length,n=0,o=0,e=!1;for(let s=0;s<c;s++){let t=a[s];t===`
`?(n++,e&&(o++,e=!1)):t===" "||t==="	"||t==="\r"?e&&(o++,e=!1):e=!0}return e&&o++,{lines:n,words:o,chars:c}}function w(a,c,n,o,e,s){let t=[];c&&t.push(String(a.lines).padStart(s)),n&&t.push(String(a.words).padStart(s)),o&&t.push(String(a.chars).padStart(s));let i=t.join(" ");return e&&(i+=` ${e}`),i}var I={name:"wc",flags:[{flag:"-l",type:"boolean"},{flag:"-w",type:"boolean"},{flag:"-c",type:"boolean"},{flag:"-m",type:"boolean"}],stdinType:"text",needsFiles:!0};export{E as a,I as b};
