#!/usr/bin/env node
import{a as g}from"./chunk-JBABAK44.js";import{a as c,b as m}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.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"]},x={delimiter:{short:"d",long:"delimiters",type:"string",default:"	"},serial:{short:"s",long:"serial",type:"boolean"}},P={name:"paste",async execute(s,i){if(m(s))return c(L);let n=g("paste",s,x);if(!n.ok)return n.error;let l=n.result.flags.delimiter,d=n.result.flags.serial,p=n.result.positional;if(p.length===0)return{stdout:"",stderr:`usage: paste [-s] [-d delimiters] file ...
`,exitCode:1};let a=i.stdin?i.stdin.split(`
`):[""];a.length>0&&a[a.length-1]===""&&a.pop();let I=p.filter(e=>e==="-").length,f=[],u=0;for(let e of p)if(e==="-"){let t=[];for(let o=u;o<a.length;o+=I)t.push(a[o]);f.push(t),u++}else{let t=i.fs.resolvePath(i.cwd,e);try{let r=(await i.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 h="";if(d)for(let e of f)e&&(h+=`${y(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]??"");h+=`${y(o,l)}
`}}return{stdout:h,stderr:"",exitCode:0}}};function y(s,i){if(s.length===0)return"";if(s.length===1)return s[0];let n=s[0];for(let l=1;l<s.length;l++){let d=(l-1)%i.length;n+=i[d]+s[l]}return n}export{P as pasteCommand};
