- Migrated native bindings from TypeScript wrappers to NAPI-RS generated modules with auto-generated type definitions and runtime enums. - Replaced chunk tree API with stateful ChunkState class supporting render, edit, and resolve operations with improved error handling. - Converted callback signatures to error-first pattern (error, result) for shell, PTY, glob, and grep operations. - Introduced type-safe enums for MacOSAppearance, GrepOutputMode, KeyEventType, ImageFormat, and AstMatchStrictness replacing string literals. - Refactored chunk tree implementation with dedicated modules for edit, indent, resolve, and state management with comprehensive validation. - Moved clipboard utilities from native bindings to coding-agent package with improved OSC 52 and Termux compatibility.
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
/**
|
|
* Test grep tool.
|
|
*/
|
|
import { GrepOutputMode } from "@oh-my-pi/pi-natives";
|
|
import { Args, Command, Flags } from "@oh-my-pi/pi-utils/cli";
|
|
import { type GrepCommandArgs, runGrepCommand } from "../cli/grep-cli";
|
|
import { initTheme } from "../modes/theme/theme";
|
|
|
|
export default class Grep extends Command {
|
|
static description = "Test grep tool";
|
|
|
|
static args = {
|
|
pattern: Args.string({ description: "Regex pattern to search for", required: false }),
|
|
path: Args.string({ description: "Directory or file to search", required: false }),
|
|
};
|
|
|
|
static flags = {
|
|
glob: Flags.string({ char: "g", description: "Filter files by glob pattern" }),
|
|
limit: Flags.integer({ char: "l", description: "Max matches", default: 20 }),
|
|
context: Flags.integer({ char: "C", description: "Context lines", default: 2 }),
|
|
files: Flags.boolean({ char: "f", description: "Output file names only" }),
|
|
count: Flags.boolean({ char: "c", description: "Output match counts per file" }),
|
|
"no-gitignore": Flags.boolean({ description: "Include files excluded by .gitignore" }),
|
|
};
|
|
|
|
async run(): Promise<void> {
|
|
const { args, flags } = await this.parse(Grep);
|
|
|
|
const mode: GrepCommandArgs["mode"] = flags.count
|
|
? GrepOutputMode.Count
|
|
: flags.files
|
|
? GrepOutputMode.FilesWithMatches
|
|
: GrepOutputMode.Content;
|
|
|
|
const cmd: GrepCommandArgs = {
|
|
pattern: args.pattern ?? "",
|
|
path: args.path ?? ".",
|
|
glob: flags.glob,
|
|
limit: flags.limit,
|
|
context: flags.context,
|
|
mode,
|
|
gitignore: !flags["no-gitignore"],
|
|
};
|
|
|
|
await initTheme();
|
|
await runGrepCommand(cmd);
|
|
}
|
|
}
|