import{r as e,t}from"./chunk-74CEPOFO-V0JXh91S.mjs";import{t as n}from"./chunk-HWKDQ44K-BJxdK4fT.mjs";var r={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`]},i={delimiter:{short:`d`,long:`delimiters`,type:`string`,default:`	`},serial:{short:`s`,long:`serial`,type:`boolean`}},a={name:`paste`,async execute(a,s){if(t(a))return e(r);let c=n(`paste`,a,i);if(!c.ok)return c.error;let l=c.result.flags.delimiter,u=c.result.flags.serial,d=c.result.positional;if(d.length===0)return{stdout:``,stderr:`usage: paste [-s] [-d delimiters] file ...
`,exitCode:1};let f=s.stdin?s.stdin.split(`
`):[``];f.length>0&&f[f.length-1]===``&&f.pop();let p=d.filter(e=>e===`-`).length,m=[],h=0;for(let e of d)if(e===`-`){let e=[];for(let t=h;t<f.length;t+=p)e.push(f[t]);m.push(e),h++}else{let t=s.fs.resolvePath(s.cwd,e);try{let e=(await s.fs.readFile(t)).split(`
`);e.length>0&&e[e.length-1]===``&&e.pop(),m.push(e)}catch{return{stdout:``,stderr:`paste: ${e}: No such file or directory
`,exitCode:1}}}let g=``;if(u)for(let e of m)e&&(g+=`${o(e,l)}
`);else{let e=Math.max(...m.map(e=>e?.length??0));for(let t=0;t<e;t++){let e=[];for(let n of m)e.push(n?.[t]??``);g+=`${o(e,l)}
`}}return{stdout:g,stderr:``,exitCode:0}}};function o(e,t){if(e.length===0)return``;if(e.length===1)return e[0];let n=e[0];for(let r=1;r<e.length;r++){let i=(r-1)%t.length;n+=t[i]+e[r]}return n}var s={name:`paste`,flags:[{flag:`-d`,type:`value`,valueHint:`delimiter`},{flag:`-s`,type:`boolean`}],stdinType:`text`,needsFiles:!0};export{s as n,a as t};
//# sourceMappingURL=chunk-JVPRLUMK-D6CRdXSO.mjs.map