feat: 添加 claw-market CLI 工具并更新 skill 使用 CLI
- 创建 pnpm monorepo 结构 (pnpm-workspace.yaml) - 添加 @ricardweii/claw-market CLI 包 - register/heartbeat/task/config 命令 - 中英文国际化支持 - JSON 输出格式支持 - 更新 openclaw-reporter skill 使用 CLI 替代 curl - 修复注册 API 返回缺少 name 字段的问题 - 更新 CLAUDE.md 文档说明 monorepo 结构
This commit is contained in:
69
packages/claw-market/src/index.ts
Normal file
69
packages/claw-market/src/index.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { Command } from "commander";
|
||||
import { detectLocale, createTranslator, type Locale } from "./i18n/index.js";
|
||||
import { registerCommand } from "./commands/register.js";
|
||||
import { heartbeatCommand } from "./commands/heartbeat.js";
|
||||
import { taskCommand } from "./commands/task.js";
|
||||
import { configCommand } from "./commands/config.js";
|
||||
import { readConfig } from "./lib/config.js";
|
||||
import { DEFAULT_ENDPOINT } from "./lib/api.js";
|
||||
|
||||
const VERSION = "0.1.1";
|
||||
|
||||
interface GlobalOptions {
|
||||
endpoint?: string;
|
||||
lang?: Locale;
|
||||
json?: boolean;
|
||||
}
|
||||
|
||||
function main(): void {
|
||||
// Pre-parse to get language option
|
||||
const preParseArgs = process.argv.slice(2);
|
||||
let langOverride: Locale | undefined;
|
||||
let jsonOutput = false;
|
||||
|
||||
for (let i = 0; i < preParseArgs.length; i++) {
|
||||
const arg = preParseArgs[i];
|
||||
if (arg === "--lang" || arg === "-l") {
|
||||
const value = preParseArgs[i + 1];
|
||||
if (value === "en" || value === "zh") {
|
||||
langOverride = value;
|
||||
}
|
||||
i++;
|
||||
} else if (arg === "--json") {
|
||||
jsonOutput = true;
|
||||
} else if (arg.startsWith("--lang=")) {
|
||||
const value = arg.split("=")[1];
|
||||
if (value === "en" || value === "zh") {
|
||||
langOverride = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Detect locale
|
||||
const config = readConfig();
|
||||
const locale = detectLocale(langOverride || config?.lang);
|
||||
const t = createTranslator(locale);
|
||||
|
||||
// Create program
|
||||
const program = new Command();
|
||||
|
||||
program
|
||||
.name("claw-market")
|
||||
.description(t("cli.description"))
|
||||
.version(VERSION)
|
||||
.option("-e, --endpoint <url>", t("global.optionEndpoint"), DEFAULT_ENDPOINT)
|
||||
.option("-l, --lang <locale>", t("global.optionLang"))
|
||||
.option("--json", t("global.optionJson"));
|
||||
|
||||
// Add commands
|
||||
registerCommand(program, t);
|
||||
heartbeatCommand(program, t);
|
||||
taskCommand(program, t);
|
||||
configCommand(program, t);
|
||||
|
||||
// Parse
|
||||
program.parse(process.argv);
|
||||
}
|
||||
|
||||
// Run main
|
||||
main();
|
||||
Reference in New Issue
Block a user