#!/usr/bin/env node
import{a as y}from"./chunk-XT766N2U.js";import{a as b}from"./chunk-JBABAK44.js";import{a as c}from"./chunk-RLNOQILG.js";import{a as f,b as u}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";var R={name:"ag-glob",async execute(p,a){if(u(p))return f({name:"ag-glob",summary:"Fast glob pattern matching over the virtual filesystem",usage:"ag-glob <pattern> [--path <dir>] [--sort mtime] [--limit <n>]",description:["Recursively walks the filesystem and returns all file paths","matching the given glob pattern. Supports standard glob syntax","including **, *, ?, and brace expansion {a,b}."],options:["-p, --path <dir>    Root directory to search from (default: cwd)","-s, --sort <mode>   Sort order: alpha (default) or mtime","-l, --limit <n>     Maximum number of results (default: 1000)"],examples:['ag-glob "**/*.ts"','ag-glob "src/**/*.{ts,tsx}" --path /project','ag-glob "*.json" --sort mtime --limit 10']});let n=b("ag-glob",p,{path:{short:"p",long:"path",type:"string"},sort:{short:"s",long:"sort",type:"string"},limit:{short:"l",long:"limit",type:"number",default:1e3}});if(!n.ok)return n.error;let{flags:m,positional:g}=n.result,d=g[0],v=m.path||g[1]||".",i=m.sort||"alpha",w=m.limit;if(!d)return{stdout:"",stderr:`Usage: ag-glob <pattern> [--path <dir>] [--sort mtime] [--limit <n>]
`,exitCode:1};if(i!=="alpha"&&i!=="mtime")return{stdout:"",stderr:`ag-glob: invalid sort mode '${i}' (expected 'alpha' or 'mtime')
`,exitCode:1};let r=a.fs.resolvePath(a.cwd,v),l=[],h=async t=>{let o=await a.fs.stat(t);if(!o.isDirectory){let e=t.startsWith(`${r}/`)?t.slice(r.length+1):t===r?t.split("/").pop()||"":t;y(e,d,{dot:!0})&&l.push({path:t,mtime:o.mtime});return}let s=await a.fs.readdir(t);for(let e of s){if(e==="node_modules"||e===".git")continue;let x=a.fs.resolvePath(t,e);await h(x)}};try{await h(r),i==="mtime"?l.sort((s,e)=>e.mtime.getTime()-s.mtime.getTime()):l.sort((s,e)=>s.path.localeCompare(e.path));let o=l.slice(0,w).map(s=>s.path);return{stdout:o.join(`
`)+(o.length>0?`
`:""),stderr:o.length===0?`No matching files found.
`:"",exitCode:0}}catch(t){return{stdout:"",stderr:`ag-glob: ${c(t.message)}
`,exitCode:1}}}};export{R as agGlobCommand};
