#!/usr/bin/env node
import{a as p}from"./chunk-JBABAK44.js";import{a as h,b as c}from"./chunk-GTNBSMZR.js";var m={name:"which",summary:"locate a command",usage:"which [-as] program ...",options:["-a         List all instances of executables found","-s         No output, just return 0 if found, 1 if not","--help     display this help and exit"]},w={showAll:{short:"a",type:"boolean"},silent:{short:"s",type:"boolean"}},x={name:"which",async execute(i,t){if(c(i))return h(m);let e=p("which",i,w);if(!e.ok)return e.error;let d=e.result.flags.showAll,a=e.result.flags.silent,l=e.result.positional;if(l.length===0)return{stdout:"",stderr:"",exitCode:1};let g=(t.env.get("PATH")||"/usr/bin:/bin").split(":"),n="",f=!0;for(let s of l){let o=!1;for(let r of g){if(!r)continue;let u=t.fs.resolvePath(r,s);if(await t.fs.exists(u)&&(o=!0,a||(n+=`${u}
`),!d))break}!o&&!s.includes("/")&&(t.getRegisteredCommands?.()??[]).includes(s)&&(o=!0,a||(n+=`/usr/bin/${s}
`)),o||(f=!1)}return{stdout:n,stderr:"",exitCode:f?0:1}}},v={name:"which",flags:[{flag:"-a",type:"boolean"},{flag:"-s",type:"boolean"}],needsArgs:!0};export{x as a,v as b};
