


















@@ -1,24 +1,35 @@
11import type { Command } from "commander";
22import { danger } from "../globals.js";
3-import { listBundledPackageChannelMetadata } from "../plugins/bundled-package-channel-metadata.js";
43import { defaultRuntime } from "../runtime.js";
54import { createLazyImportLoader } from "../shared/lazy-promise.js";
65import { formatDocsLink } from "../terminal/links.js";
76import { theme } from "../terminal/theme.js";
7+import { resolveCliArgvInvocation } from "./argv-invocation.js";
88import { runChannelLogin, runChannelLogout } from "./channel-auth.js";
99import { formatCliChannelOptions } from "./channel-options.js";
1010import { runCommandWithRuntime } from "./cli-utils.js";
1111import { hasExplicitOptions } from "./command-options.js";
1212import { formatHelpExamples } from "./help-format.js";
1313import { applyParentDefaultHelpAction } from "./program/parent-default-help.js";
14+import { normalizeWindowsArgv } from "./windows-argv.js";
14151516type ChannelsCommandsModule = typeof import("../commands/channels.js");
17+type BundledPackageChannelMetadataModule =
18+typeof import("../plugins/bundled-package-channel-metadata.js");
16191720const optionNamesRemove = ["channel", "account", "delete"] as const;
182122+type RegisterChannelsCliOptions = {
23+includeSetupOptions?: boolean;
24+};
25+1926const channelsCommandsLoader = createLazyImportLoader<ChannelsCommandsModule>(
2027() => import("../commands/channels.js"),
2128);
29+const bundledPackageChannelMetadataLoader =
30+createLazyImportLoader<BundledPackageChannelMetadataModule>(
31+() => import("../plugins/bundled-package-channel-metadata.js"),
32+);
22332334function loadChannelsCommands(): Promise<ChannelsCommandsModule> {
2435return channelsCommandsLoader.load();
@@ -39,7 +50,19 @@ function getOptionNames(command: Command): string[] {
3950return command.options.map((option) => option.attributeName());
4051}
415242-function addChannelSetupOptions(command: Command): Command {
53+function shouldRegisterChannelSetupOptions(
54+argv: string[] = process.argv,
55+options: RegisterChannelsCliOptions = {},
56+): boolean {
57+if (options.includeSetupOptions) {
58+return true;
59+}
60+const { commandPath } = resolveCliArgvInvocation(normalizeWindowsArgv(argv));
61+return commandPath[0] === "channels" && commandPath[1] === "add";
62+}
63+64+async function addChannelSetupOptions(command: Command): Promise<Command> {
65+const { listBundledPackageChannelMetadata } = await bundledPackageChannelMetadataLoader.load();
4366const seenFlags = new Set(command.options.map((option) => option.flags));
4467const channels = listBundledPackageChannelMetadata().toSorted((left, right) => {
4568const leftOrder = left.order ?? Number.MAX_SAFE_INTEGER;
@@ -64,7 +87,11 @@ function addChannelSetupOptions(command: Command): Command {
6487return command;
6588}
668967-export function registerChannelsCli(program: Command) {
90+export async function registerChannelsCli(
91+program: Command,
92+argv: string[] = process.argv,
93+options: RegisterChannelsCliOptions = {},
94+) {
6895const channelNames = formatCliChannelOptions();
6996const channels = program
7097.command("channels")
@@ -163,27 +190,31 @@ export function registerChannelsCli(program: Command) {
163190});
164191});
165192166-addChannelSetupOptions(
167-channels
168-.command("add")
169-.description("Add or update a channel account")
170-.option("--channel <name>", `Channel (${channelNames})`)
171-.option("--account <id>", "Account id (default when omitted)")
172-.option("--name <name>", "Display name for this account")
173-.option("--token <token>", "Channel token or credential payload")
174-.option("--token-file <path>", "Read channel token or credential payload from file")
175-.option("--secret <secret>", "Channel shared secret")
176-.option("--secret-file <path>", "Read channel shared secret from file")
177-.option("--bot-token <token>", "Bot token")
178-.option("--app-token <token>", "App token")
179-.option("--password <password>", "Channel password or login secret")
180-.option("--cli-path <path>", "Channel CLI path")
181-.option("--url <url>", "Channel setup URL")
182-.option("--base-url <url>", "Channel base URL")
183-.option("--http-url <url>", "Channel HTTP service URL")
184-.option("--auth-dir <path>", "Channel auth directory override")
185-.option("--use-env", "Use env-backed credentials when supported", false),
186-).action(async (opts, command) => {
193+const addCommand = channels
194+.command("add")
195+.description("Add or update a channel account")
196+.option("--channel <name>", `Channel (${channelNames})`)
197+.option("--account <id>", "Account id (default when omitted)")
198+.option("--name <name>", "Display name for this account")
199+.option("--token <token>", "Channel token or credential payload")
200+.option("--token-file <path>", "Read channel token or credential payload from file")
201+.option("--secret <secret>", "Channel shared secret")
202+.option("--secret-file <path>", "Read channel shared secret from file")
203+.option("--bot-token <token>", "Bot token")
204+.option("--app-token <token>", "App token")
205+.option("--password <password>", "Channel password or login secret")
206+.option("--cli-path <path>", "Channel CLI path")
207+.option("--url <url>", "Channel setup URL")
208+.option("--base-url <url>", "Channel base URL")
209+.option("--http-url <url>", "Channel HTTP service URL")
210+.option("--auth-dir <path>", "Channel auth directory override")
211+.option("--use-env", "Use env-backed credentials when supported", false);
212+213+if (shouldRegisterChannelSetupOptions(argv, options)) {
214+await addChannelSetupOptions(addCommand);
215+}
216+217+addCommand.action(async (opts, command) => {
187218await runChannelsCommand(async () => {
188219const { channelsAddCommand } = await loadChannelsCommands();
189220const hasFlags = hasExplicitOptions(command, getOptionNames(command));
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。