import{a as u}from"./chunk-HWKDQ44K.js";import{a as p}from"./chunk-3THT3N7L.js";var v={name:"ag-grep",async execute(d,t){let a=u("ag-grep",d,{path:{short:"p",long:"path",type:"string"},query:{short:"q",long:"query",type:"string"},ignoreCase:{short:"i",long:"ignore-case",type:"boolean"}});if(!a.ok)return a.error;let{flags:i,positional:l}=a.result,g=i.query||l[0],h=i.path||l[1]||".";if(!g)return{stdout:"",stderr:`Usage: ag-grep <query> [path] [--ignore-case]
`,exitCode:1};let y=t.fs.resolvePath(t.cwd,h),o=[],f=async e=>{if(!(await t.fs.stat(e)).isDirectory){let s=(await t.fs.readFile(e,"utf8")).split(`
`);for(let r=0;r<s.length;r++){let c=!1;i.ignoreCase?c=s[r].toLowerCase().includes(g.toLowerCase()):c=s[r].includes(g),c&&o.push(`${e}:${r+1}:${s[r]}`)}return}let m=await t.fs.readdir(e);for(let n of m){let s=t.fs.resolvePath(e,n);n==="node_modules"||n===".git"||await f(s)}};try{return await f(y),{stdout:o.join(`
`)+(o.length>0?`
`:""),stderr:o.length===0?`No matches found.
`:"",exitCode:0}}catch(e){return{stdout:"",stderr:`ag-grep: ${p(e.message)}
`,exitCode:1}}}};export{v as a};
