import{c as m}from"./chunk-AH77CRWX.js";import{a as x}from"./chunk-HWKDQ44K.js";import{a as g,b as y}from"./chunk-74CEPOFO.js";var L={name:"paste",summary:"merge lines of files",usage:"paste [OPTION]... [FILE]...",description:["Write lines consisting of the sequentially corresponding lines from","each FILE, separated by TABs, to standard output.","","With no FILE, or when FILE is -, read standard input."],options:["-d, --delimiters=LIST   reuse characters from LIST instead of TABs","-s, --serial            paste one file at a time instead of in parallel","    --help              display this help and exit"],examples:["paste file1 file2       Merge file1 and file2 side by side","paste -d, file1 file2   Use comma as delimiter","paste -s file1          Paste all lines of file1 on one line","paste - - < file        Paste pairs of lines from file"]},T={delimiter:{short:"d",long:"delimiters",type:"string",default:"	"},serial:{short:"s",long:"serial",type:"boolean"}},w={name:"paste",async execute(s,n){if(y(s))return g(L);let i=x("paste",s,T);if(!i.ok)return i.error;let l=i.result.flags.delimiter,d=i.result.flags.serial,p=i.result.positional;if(p.length===0)return{stdout:"",stderr:`usage: paste [-s] [-d delimiters] file ...
`,exitCode:1};let c=m(n.stdin),a=c?c.split(`
`):[""];a.length>0&&a[a.length-1]===""&&a.pop();let F=p.filter(e=>e==="-").length,f=[],h=0;for(let e of p)if(e==="-"){let t=[];for(let o=h;o<a.length;o+=F)t.push(a[o]);f.push(t),h++}else{let t=n.fs.resolvePath(n.cwd,e);try{let r=(await n.fs.readFile(t)).split(`
`);r.length>0&&r[r.length-1]===""&&r.pop(),f.push(r)}catch{return{stdout:"",stderr:`paste: ${e}: No such file or directory
`,exitCode:1}}}let u="";if(d)for(let e of f)e&&(u+=`${I(e,l)}
`);else{let e=Math.max(...f.map(t=>t?.length??0));for(let t=0;t<e;t++){let o=[];for(let r of f)o.push(r?.[t]??"");u+=`${I(o,l)}
`}}return{stdout:u,stderr:"",exitCode:0}}};function I(s,n){if(s.length===0)return"";if(s.length===1)return s[0];let i=s[0];for(let l=1;l<s.length;l++){let d=(l-1)%n.length;i+=n[d]+s[l]}return i}var E={name:"paste",flags:[{flag:"-d",type:"value",valueHint:"delimiter"},{flag:"-s",type:"boolean"}],stdinType:"text",needsFiles:!0};export{w as a,E as b};
