import{n as e,r as t,t as n}from"./chunk-74CEPOFO-V0JXh91S.mjs";var r={name:`unexpand`,summary:`convert spaces to tabs`,usage:`unexpand [OPTION]... [FILE]...`,description:`Convert blanks in each FILE to TABs, writing to standard output. If no FILE is specified, standard input is read.`,options:[`-t N        Use N spaces per tab (default: 8)`,`-t LIST     Use comma-separated list of tab stops`,`-a          Convert all sequences of blanks (not just leading)`],examples:[`unexpand file.txt           # Convert leading spaces to tabs`,`unexpand -a file.txt        # Convert all space sequences`,`unexpand -t 4 file.txt      # Use 4-space tabs`]};function i(e){let t=e.split(`,`).map(e=>e.trim()),n=[];for(let e of t){let t=parseInt(e,10);if(Number.isNaN(t)||t<1)return null;n.push(t)}for(let e=1;e<n.length;e++)if(n[e]<=n[e-1])return null;return n}function a(e,t){if(t.length===1){let n=t[0];return e+(n-e%n)}for(let n of t)if(n>e)return n;if(t.length>=2){let n=t[t.length-1]-t[t.length-2],r=t[t.length-1];return r+(Math.floor((e-r)/n)+1)*n}return-1}function o(e,t){let{tabStops:n,allBlanks:r}=t,i=``,o=0,s=``,c=0,l=!0,u=()=>{if(s.length===0)return;let e=c+s.length;if(!r&&!l){i+=s,s=``;return}let t=c,o=``;for(;t<e;){let r=a(t,n);if(r<=e&&r>t)o+=`	`,t=r;else break}let u=e-t;u>0&&(o+=` `.repeat(u)),i+=o,s=``};for(let t of e)t===` `?(s.length===0&&(c=o),s+=t,o++):t===`	`?(u(),i+=t,o=a(o,n)):(u(),i+=t,o++,l=!1);return u(),i}function s(e,t){if(e===``)return``;let n=e.split(`
`),r=e.endsWith(`
`)&&n[n.length-1]===``;return r&&n.pop(),n.map(e=>o(e,t)).join(`
`)+(r?`
`:``)}var c={name:`unexpand`,execute:async(a,o)=>{if(n(a))return t(r);let c={tabStops:[8],allBlanks:!1},l=[],u=0;for(;u<a.length;){let t=a[u];if(t===`-t`&&u+1<a.length){let e=i(a[u+1]);if(!e)return{exitCode:1,stdout:``,stderr:`unexpand: invalid tab size: '${a[u+1]}'
`};c.tabStops=e,u+=2}else if(t.startsWith(`-t`)&&t.length>2){let e=i(t.slice(2));if(!e)return{exitCode:1,stdout:``,stderr:`unexpand: invalid tab size: '${t.slice(2)}'
`};c.tabStops=e,u++}else if(t===`--tabs`&&u+1<a.length){let e=i(a[u+1]);if(!e)return{exitCode:1,stdout:``,stderr:`unexpand: invalid tab size: '${a[u+1]}'
`};c.tabStops=e,u+=2}else if(t.startsWith(`--tabs=`)){let e=i(t.slice(7));if(!e)return{exitCode:1,stdout:``,stderr:`unexpand: invalid tab size: '${t.slice(7)}'
`};c.tabStops=e,u++}else if(t===`-a`||t===`--all`)c.allBlanks=!0,u++;else if(t===`--`){l.push(...a.slice(u+1));break}else{if(t.startsWith(`-`)&&t!==`-`)return e(`unexpand`,t);l.push(t),u++}}let d=``;if(l.length===0)d=s(o.stdin??``,c);else for(let e of l){let t=o.fs.resolvePath(o.cwd,e),n=await o.fs.readFile(t);if(n===null)return{exitCode:1,stdout:d,stderr:`unexpand: ${e}: No such file or directory
`};d+=s(n,c)}return{exitCode:0,stdout:d,stderr:``}}},l={name:`unexpand`,flags:[{flag:`-t`,type:`value`,valueHint:`number`},{flag:`-a`,type:`boolean`}],stdinType:`text`,needsFiles:!0};export{c as n,l as t};
//# sourceMappingURL=chunk-PYSFUGCK-B_Gv8rUn.mjs.map