diff --git a/src/cli/cli-program.ts b/src/cli/cli-program.ts index fc8fdfd0a..cb5df4b81 100644 --- a/src/cli/cli-program.ts +++ b/src/cli/cli-program.ts @@ -32,6 +32,10 @@ type InstallCommandOptions = { readonly skipAuth?: boolean } +type RootCommandOptions = { + readonly platform?: InstallArgs["platform"] +} + export function resolveInstallArgs( options: InstallCommandOptions, invocationName: string | undefined = process.env.OMO_INVOCATION_NAME, @@ -60,6 +64,7 @@ program .description("The ultimate OpenCode plugin - multi-model orchestration, LSP tools, and more") .version(VERSION, "-v, --version", "Show version number") .helpOption("-h, --help", "Display help for command") + .addOption(new Option("--platform ", "Install target platform: opencode, codex, both").choices(["opencode", "codex", "both"]).hideHelp()) .enablePositionalOptions() program @@ -98,8 +103,9 @@ Model Providers (Priority: Native > Copilot > OpenCode Zen > Z.ai > Kimi > Verce Kimi kimi-for-coding/k2p5 (Sisyphus/Prometheus fallback) Vercel vercel/ models (universal proxy, always last fallback) `) - .action(async (options) => { - const args = resolveInstallArgs(options) + .action(async (options: InstallCommandOptions) => { + const rootOptions = program.opts() + const args = resolveInstallArgs({ ...options, platform: options.platform ?? rootOptions.platform }) const exitCode = await install(args) process.exit(exitCode) }) diff --git a/src/cli/install-platform-resolution.test.ts b/src/cli/install-platform-resolution.test.ts index e204eb6b2..3c6d97ff0 100644 --- a/src/cli/install-platform-resolution.test.ts +++ b/src/cli/install-platform-resolution.test.ts @@ -106,4 +106,18 @@ describe("install platform resolution", () => { expect(installBlock?.[1]).toContain("--codex-autonomous") expect(installBlock?.[1]).toContain("--no-codex-autonomous") }) + + test("defines root --platform so npx can pass it before install", async () => { + // given + const cliProgramSource = await Bun.file(new URL("./cli-program.ts", import.meta.url)).text() + + // when + const rootBlock = cliProgramSource.match(/program\s*\n\s*\.name\("oh-my-opencode"\)([\s\S]*?)\.enablePositionalOptions\(\)/) + + // then + expect(rootBlock).not.toBeNull() + expect(rootBlock?.[1]).toContain('new Option("--platform "') + expect(rootBlock?.[1]).toContain('.choices(["opencode", "codex", "both"])') + expect(rootBlock?.[1]).toContain(".hideHelp()") + }) })