cloudaxe-opencode/packages/opencode/src/cli/cmd/debug/file.ts

98 lines
2.5 KiB
TypeScript
Raw Normal View History

import { EOL } from "os"
2025-07-01 16:06:38 +00:00
import { File } from "../../../file"
import { bootstrap } from "../../bootstrap"
import { cmd } from "../cmd"
2025-11-17 15:57:18 +00:00
import { Ripgrep } from "@/file/ripgrep"
2025-07-01 16:06:38 +00:00
const FileSearchCommand = cmd({
command: "search <query>",
describe: "search files by query",
builder: (yargs) =>
yargs.positional("query", {
type: "string",
demandOption: true,
description: "Search query",
}),
async handler(args) {
await bootstrap(process.cwd(), async () => {
const results = await File.search({ query: args.query })
process.stdout.write(results.join(EOL) + EOL)
})
},
})
2025-07-01 16:06:38 +00:00
const FileReadCommand = cmd({
command: "read <path>",
describe: "read file contents as JSON",
2025-07-01 16:06:38 +00:00
builder: (yargs) =>
yargs.positional("path", {
type: "string",
demandOption: true,
description: "File path to read",
}),
async handler(args) {
await bootstrap(process.cwd(), async () => {
2025-07-02 00:06:11 +00:00
const content = await File.read(args.path)
process.stdout.write(JSON.stringify(content, null, 2) + EOL)
2025-07-01 16:06:38 +00:00
})
},
})
2025-07-02 00:39:43 +00:00
const FileStatusCommand = cmd({
command: "status",
describe: "show file status information",
2025-07-02 00:39:43 +00:00
builder: (yargs) => yargs,
async handler() {
await bootstrap(process.cwd(), async () => {
2025-07-02 00:39:43 +00:00
const status = await File.status()
process.stdout.write(JSON.stringify(status, null, 2) + EOL)
2025-07-02 00:39:43 +00:00
})
},
})
2025-08-27 20:27:49 +00:00
const FileListCommand = cmd({
command: "list <path>",
describe: "list files in a directory",
2025-08-27 20:27:49 +00:00
builder: (yargs) =>
yargs.positional("path", {
type: "string",
demandOption: true,
description: "File path to list",
}),
async handler(args) {
await bootstrap(process.cwd(), async () => {
2025-08-27 20:27:49 +00:00
const files = await File.list(args.path)
process.stdout.write(JSON.stringify(files, null, 2) + EOL)
2025-08-27 20:27:49 +00:00
})
},
})
2025-11-17 15:57:18 +00:00
const FileTreeCommand = cmd({
command: "tree [dir]",
describe: "show directory tree",
2025-11-17 15:57:18 +00:00
builder: (yargs) =>
yargs.positional("dir", {
type: "string",
description: "Directory to tree",
default: process.cwd(),
}),
async handler(args) {
const files = await Ripgrep.tree({ cwd: args.dir, limit: 200 })
console.log(JSON.stringify(files, null, 2))
2025-11-17 15:57:18 +00:00
},
})
2025-07-02 00:39:43 +00:00
export const FileCommand = cmd({
command: "file",
describe: "file system debugging utilities",
2025-08-27 20:27:49 +00:00
builder: (yargs) =>
yargs
.command(FileReadCommand)
.command(FileStatusCommand)
.command(FileListCommand)
.command(FileSearchCommand)
2025-11-17 15:57:18 +00:00
.command(FileTreeCommand)
.demandCommand(),
2025-07-02 00:39:43 +00:00
async handler() {},
})