mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-21 10:16:44 +00:00
feat: accept positional channels in setup
This commit is contained in:
@@ -3,7 +3,7 @@ import { Command } from "commander";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { PluginPackageChannel } from "../plugins/manifest.js";
|
||||
import { mockProcessPlatform } from "../test-utils/vitest-spies.js";
|
||||
import { registerChannelsCli } from "./channels-cli.js";
|
||||
import { registerChannelsCli, resolveChannelsAddOptions } from "./channels-cli.js";
|
||||
|
||||
const listBundledPackageChannelMetadataMock = vi.hoisted(() =>
|
||||
vi.fn<() => readonly PluginPackageChannel[]>(() => []),
|
||||
@@ -97,3 +97,23 @@ describe("registerChannelsCli", () => {
|
||||
expect(getChannelAddOptionFlags(program)).toContain("--homeserver <url>");
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveChannelsAddOptions", () => {
|
||||
it("accepts a positional channel while preserving --channel precedence", () => {
|
||||
expect(
|
||||
resolveChannelsAddOptions("clickclack", {
|
||||
baseUrl: "https://clickclack.example",
|
||||
token: "ccb_test",
|
||||
workspace: "default",
|
||||
}),
|
||||
).toEqual({
|
||||
channel: "clickclack",
|
||||
baseUrl: "https://clickclack.example",
|
||||
token: "ccb_test",
|
||||
workspace: "default",
|
||||
});
|
||||
expect(resolveChannelsAddOptions("clickclack", { channel: "telegram" })).toEqual({
|
||||
channel: "telegram",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+15
-2
@@ -51,6 +51,16 @@ function getOptionNames(command: Command): string[] {
|
||||
return command.options.map((option) => option.attributeName());
|
||||
}
|
||||
|
||||
export function resolveChannelsAddOptions(
|
||||
channelArg: string | undefined,
|
||||
opts: Record<string, unknown>,
|
||||
): Record<string, unknown> {
|
||||
return {
|
||||
...opts,
|
||||
channel: opts.channel ?? channelArg,
|
||||
};
|
||||
}
|
||||
|
||||
function shouldRegisterChannelSetupOptions(
|
||||
argv: string[] = process.argv,
|
||||
options: RegisterChannelsCliOptions = {},
|
||||
@@ -198,6 +208,7 @@ export async function registerChannelsCli(
|
||||
const addCommand = channels
|
||||
.command("add")
|
||||
.description("Add or update a channel account")
|
||||
.argument("[channel]", "Channel id")
|
||||
.addHelpText(
|
||||
"after",
|
||||
() =>
|
||||
@@ -231,11 +242,13 @@ export async function registerChannelsCli(
|
||||
await addChannelSetupOptions(addCommand);
|
||||
}
|
||||
|
||||
addCommand.action(async (opts, command) => {
|
||||
addCommand.action(async (channelArg: string | undefined, opts, command) => {
|
||||
await runChannelsCommand(async () => {
|
||||
const { channelsAddCommand } = await loadChannelsCommands();
|
||||
const hasFlags = hasExplicitOptions(command, getOptionNames(command));
|
||||
await channelsAddCommand(opts, defaultRuntime, { hasFlags });
|
||||
await channelsAddCommand(resolveChannelsAddOptions(channelArg, opts), defaultRuntime, {
|
||||
hasFlags,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user