import{a as m,b as d,c as f}from"./chunk-74CEPOFO.js";import"./chunk-DXB73IDG.js";var w={name:"env",summary:"run a program in a modified environment",usage:"env [OPTION]... [NAME=VALUE]... [COMMAND [ARG]...]",options:["-i, --ignore-environment  start with an empty environment","-u NAME, --unset=NAME     remove NAME from the environment","    --help                display this help and exit"]},C={name:"env",async execute(o,l){if(d(o))return m(w);let a=!1,i=[],c=new Map,t=-1;for(let n=0;n<o.length;n++){let e=o[n];if(e==="-i"||e==="--ignore-environment")a=!0;else if(e==="-u"&&n+1<o.length)i.push(o[++n]);else if(e.startsWith("-u"))i.push(e.slice(2));else if(e.startsWith("--unset="))i.push(e.slice(8));else{if(e.startsWith("--")&&e!=="--")return f("env",e);if(e.startsWith("-")&&e!=="-"){for(let r of e.slice(1))if(r!=="i"&&r!=="u")return f("env",`-${r}`);e.includes("i")&&(a=!0)}else if(e.includes("=")&&t===-1){let r=e.indexOf("="),$=e.slice(0,r),g=e.slice(r+1);c.set($,g)}else{t=n;break}}}let s;if(a)s=new Map(c);else{s=new Map(l.env);for(let n of i)s.delete(n);for(let[n,e]of c)s.set(n,e)}if(t===-1){let n=[];for(let[e,r]of s)n.push(`${e}=${r}`);return{stdout:n.join(`
`)+(n.length>0?`
`:""),stderr:"",exitCode:0}}if(!l.exec)return{stdout:"",stderr:`env: command execution not supported in this context
`,exitCode:1};let u=o.slice(t),h=u[0],x=u.slice(1).map(n=>/[\s"'\\$`!*?[\]{}|&;<>()]/.test(n)?`'${n.replace(/'/g,"'\\''")}'`:n),p=["command",h,...x].join(" "),v=Object.entries(c).map(([n,e])=>`${n}="${e}"`).join(" "),A=v?`${v} ${p}`:p;return l.exec(A,{cwd:l.cwd})}},y={name:"printenv",summary:"print all or part of environment",usage:"printenv [OPTION]... [VARIABLE]...",options:["    --help       display this help and exit"]},E={name:"printenv",async execute(o,l){if(d(o))return m(y);let a=o.filter(t=>!t.startsWith("-"));if(a.length===0){let t=[];for(let[s,u]of l.env)t.push(`${s}=${u}`);return{stdout:t.join(`
`)+(t.length>0?`
`:""),stderr:"",exitCode:0}}let i=[],c=0;for(let t of a){let s=l.env.get(t);s!==void 0?i.push(s):c=1}return{stdout:i.join(`
`)+(i.length>0?`
`:""),stderr:"",exitCode:c}}};export{C as envCommand,E as printenvCommand};
