import{r as e}from"./chunk-OJDRYQWQ-CmrD0Dg2.mjs";import{n as t,r as n,t as r}from"./chunk-74CEPOFO-V0JXh91S.mjs";var i={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`]},a={name:`env`,async execute(a,o){if(r(a))return n(i);let s=!1,c=[],l=new Map,u=-1;for(let e=0;e<a.length;e++){let n=a[e];if(n===`-i`||n===`--ignore-environment`)s=!0;else if(n===`-u`&&e+1<a.length)c.push(a[++e]);else if(n.startsWith(`-u`))c.push(n.slice(2));else if(n.startsWith(`--unset=`))c.push(n.slice(8));else{if(n.startsWith(`--`)&&n!==`--`)return t(`env`,n);if(n.startsWith(`-`)&&n!==`-`){for(let e of n.slice(1))if(e!==`i`&&e!==`u`)return t(`env`,`-${e}`);n.includes(`i`)&&(s=!0)}else if(n.includes(`=`)&&u===-1){let e=n.indexOf(`=`),t=n.slice(0,e),r=n.slice(e+1);l.set(t,r)}else{u=e;break}}}let d;if(s)d=new Map(l);else{d=new Map(o.env);for(let e of c)d.delete(e);for(let[e,t]of l)d.set(e,t)}if(u===-1){let e=[];for(let[t,n]of d)e.push(`${t}=${n}`);return{stdout:e.join(`
`)+(e.length>0?`
`:``),stderr:``,exitCode:0}}if(!o.exec)return{stdout:``,stderr:`env: command execution not supported in this context
`,exitCode:1};let f=a.slice(u);return o.exec(`command`,{cwd:o.cwd,env:e(d),replaceEnv:!0,stdin:o.stdin,signal:o.signal,args:f})}},o={name:`printenv`,summary:`print all or part of environment`,usage:`printenv [OPTION]... [VARIABLE]...`,options:[`    --help       display this help and exit`]},s={name:`printenv`,async execute(e,t){if(r(e))return n(o);let i=e.filter(e=>!e.startsWith(`-`));if(i.length===0){let e=[];for(let[n,r]of t.env)e.push(`${n}=${r}`);return{stdout:e.join(`
`)+(e.length>0?`
`:``),stderr:``,exitCode:0}}let a=[],s=0;for(let e of i){let n=t.env.get(e);n===void 0?s=1:a.push(n)}return{stdout:a.join(`
`)+(a.length>0?`
`:``),stderr:``,exitCode:s}}},c={name:`env`,flags:[{flag:`-i`,type:`boolean`},{flag:`-u`,type:`value`,valueHint:`string`}]},l={name:`printenv`,flags:[]};export{a as i,c as n,l as r,s as t};
//# sourceMappingURL=chunk-NAERJDUW-Cyg2DAzO.mjs.map