feat(read): replace offset/limit with sel parameter for line ranges and chunk selectors

This commit is contained in:
can1357
2026-04-06 18:40:56 +02:00
parent 03fd34de63
commit 4258ca3b8a
9 changed files with 356 additions and 43 deletions
+36
View File
@@ -0,0 +1,36 @@
/**
* Read CLI command handler.
*
* Handles `omp read` subcommand — emits chunk-mode read output for a file.
*/
import * as path from "node:path";
import chalk from "chalk";
import { getLanguageFromPath } from "../modes/theme/theme";
import { formatChunkedRead } from "../tools/chunk-tree";
export interface ReadCommandArgs {
path: string;
sel?: string;
}
export async function runReadCommand(cmd: ReadCommandArgs): Promise<void> {
const filePath = path.resolve(cmd.path);
const file = Bun.file(filePath);
if (!(await file.exists())) {
console.error(chalk.red(`Error: File not found: ${cmd.path}`));
process.exit(1);
}
const readPath = cmd.sel ? `${filePath}:${cmd.sel}` : filePath;
const language = getLanguageFromPath(filePath);
const cwd = process.cwd();
try {
const result = await formatChunkedRead({ filePath, readPath, cwd, language });
console.log(result.text);
} catch (err) {
console.error(chalk.red(`Error: ${err instanceof Error ? err.message : String(err)}`));
process.exit(1);
}
}