Files
QR-master/.output/server/node_modules/just-bash/dist/bundle/chunks/chunk-AAGO7IQ5.js
2026-07-15 18:08:51 +02:00

12 lines
3.0 KiB
JavaScript

import{createRequire} from"node:module";const require=createRequire(import.meta.url);
import{c as g}from"./chunk-XEKXHOPO.js";import{a as b,b as m,c as v}from"./chunk-QAYAQNCG.js";var L={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 f(s){let i=s.split(",").map(o=>o.trim()),e=[];for(let o of i){let n=parseInt(o,10);if(Number.isNaN(n)||n<1)return null;e.push(n)}for(let o=1;o<e.length;o++)if(e[o]<=e[o-1])return null;return e}function C(s,i){if(i.length===1){let e=i[0];return s+(e-s%e)}for(let e of i)if(e>s)return e;if(i.length>=2){let e=i[i.length-1]-i[i.length-2],o=i[i.length-1],n=Math.floor((s-o)/e)+1;return o+n*e}return-1}function N(s,i){let{tabStops:e,allBlanks:o}=i,n="",a=0,t="",l=0,u=!0,d=()=>{if(t.length===0)return;let r=l+t.length;if(!o&&!u){n+=t,t="";return}let p=l,c="";for(;p<r;){let h=C(p,e);if(h<=r&&h>p)c+=" ",p=h;else break}let x=r-p;x>0&&(c+=" ".repeat(x)),n+=c,t=""};for(let r of s)r===" "?(t.length===0&&(l=a),t+=r,a++):r===" "?(d(),n+=r,a=C(a,e)):(d(),n+=r,a++,u=!1);return d(),n}function k(s,i){if(s==="")return"";let e=s.split(`
`),o=s.endsWith(`
`)&&e[e.length-1]==="";return o&&e.pop(),e.map(a=>N(a,i)).join(`
`)+(o?`
`:"")}var I={name:"unexpand",execute:async(s,i)=>{if(m(s))return b(L);let e={tabStops:[8],allBlanks:!1},o=[],n=0;for(;n<s.length;){let t=s[n];if(t==="-t"&&n+1<s.length){let l=f(s[n+1]);if(!l)return{exitCode:1,stdout:"",stderr:`unexpand: invalid tab size: '${s[n+1]}'
`};e.tabStops=l,n+=2}else if(t.startsWith("-t")&&t.length>2){let l=f(t.slice(2));if(!l)return{exitCode:1,stdout:"",stderr:`unexpand: invalid tab size: '${t.slice(2)}'
`};e.tabStops=l,n++}else if(t==="--tabs"&&n+1<s.length){let l=f(s[n+1]);if(!l)return{exitCode:1,stdout:"",stderr:`unexpand: invalid tab size: '${s[n+1]}'
`};e.tabStops=l,n+=2}else if(t.startsWith("--tabs=")){let l=f(t.slice(7));if(!l)return{exitCode:1,stdout:"",stderr:`unexpand: invalid tab size: '${t.slice(7)}'
`};e.tabStops=l,n++}else if(t==="-a"||t==="--all")e.allBlanks=!0,n++;else if(t==="--"){o.push(...s.slice(n+1));break}else{if(t.startsWith("-")&&t!=="-")return v("unexpand",t);o.push(t),n++}}let a="";if(o.length===0){let t=g(i.stdin)??"";a=k(t,e)}else for(let t of o){let l=i.fs.resolvePath(i.cwd,t),u=await i.fs.readFile(l);if(u===null)return{exitCode:1,stdout:a,stderr:`unexpand: ${t}: No such file or directory
`};a+=k(u,e)}return{exitCode:0,stdout:a,stderr:""}}},T={name:"unexpand",flags:[{flag:"-t",type:"value",valueHint:"number"},{flag:"-a",type:"boolean"}],stdinType:"text",needsFiles:!0};export{I as a,T as b};