import{a as y,b,c as A}from"./chunk-74CEPOFO.js";import"./chunk-DXB73IDG.js";var E={name:"xargs",summary:"build and execute command lines from standard input",usage:"xargs [OPTION]... [COMMAND [INITIAL-ARGS]]",options:["-I REPLACE   replace occurrences of REPLACE with input","-d DELIM     use DELIM as input delimiter (e.g., -d '\\n' for newline)","-n NUM       use at most NUM arguments per command line","-P NUM       run at most NUM processes at a time","-0, --null   items are separated by null, not whitespace","-t, --verbose  print commands before executing","-r, --no-run-if-empty  do not run command if input is empty","    --help   display this help and exit"]},P={name:"xargs",async execute(s,i){if(b(s))return y(E);let p=null,h=null,c=null,o=null,g=!1,x=!1,C=!1,l=0;for(let e=0;e<s.length;e++){let t=s[e];if(t==="-I"&&e+1<s.length)p=s[++e],l=e+1;else if(t==="-d"&&e+1<s.length)h=s[++e].replace(/\\n/g,`
`).replace(/\\t/g,"	").replace(/\\r/g,"\r").replace(/\\0/g,"\0").replace(/\\\\/g,"\\"),l=e+1;else if(t==="-n"&&e+1<s.length)c=parseInt(s[++e],10),l=e+1;else if(t==="-P"&&e+1<s.length)o=parseInt(s[++e],10),l=e+1;else if(t==="-0"||t==="--null")g=!0,l=e+1;else if(t==="-t"||t==="--verbose")x=!0,l=e+1;else if(t==="-r"||t==="--no-run-if-empty")C=!0,l=e+1;else{if(t.startsWith("--"))return A("xargs",t);if(t.startsWith("-")&&t.length>1){for(let n of t.slice(1))if(!"0tr".includes(n))return A("xargs",`-${n}`);t.includes("0")&&(g=!0),t.includes("t")&&(x=!0),t.includes("r")&&(C=!0),l=e+1}else if(!t.startsWith("-")){l=e;break}}}let a=s.slice(l);a.length===0&&a.push("echo");let r;if(g?r=i.stdin.split("\0").filter(e=>e.length>0):h!==null?r=i.stdin.replace(/\n$/,"").split(h).filter(t=>t.length>0):r=i.stdin.split(/\s+/).map(e=>e.trim()).filter(e=>e.length>0),r.length===0)return C?{stdout:"",stderr:"",exitCode:0}:{stdout:"",stderr:"",exitCode:0};let d="",u="",f=0,M=e=>/[\s"'\\$`!*?[\]{}();&|<>#]/.test(e)?`"${e.replace(/([\\"`$])/g,"\\$1")}"`:e,w=async e=>{let t=e.map(M).join(" ");return x&&(u+=`${t}
`),i.exec?i.exec(t,{cwd:i.cwd}):{stdout:`${t}
`,stderr:"",exitCode:0}},I=async e=>{if(o!==null&&o>1)for(let t=0;t<e.length;t+=o){let n=e.slice(t,t+o),$=await Promise.all(n.map(w));for(let m of $)d+=m.stdout,u+=m.stderr,m.exitCode!==0&&(f=m.exitCode)}else for(let t of e){let n=await w(t);d+=n.stdout,u+=n.stderr,n.exitCode!==0&&(f=n.exitCode)}};if(p!==null){let e=r.map(t=>a.map(n=>n.replaceAll(p,t)));await I(e)}else if(c!==null){let e=[];for(let t=0;t<r.length;t+=c){let n=r.slice(t,t+c);e.push([...a,...n])}await I(e)}else{let e=[...a,...r],t=await w(e);d+=t.stdout,u+=t.stderr,f=t.exitCode}return{stdout:d,stderr:u,exitCode:f}}};export{P as xargsCommand};
