mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-25 03:04:29 -04:00
refactor(cli): share configure section runner
This commit is contained in:
@@ -293,27 +293,8 @@ export function registerConfigCli(program: Command) {
|
||||
[] as string[],
|
||||
)
|
||||
.action(async (opts) => {
|
||||
const {
|
||||
CONFIGURE_WIZARD_SECTIONS,
|
||||
configureCommand,
|
||||
configureCommandWithSections,
|
||||
parseConfigureWizardSections,
|
||||
} = await import("../commands/configure.js");
|
||||
const { sections, invalid } = parseConfigureWizardSections(opts.section);
|
||||
if (sections.length === 0) {
|
||||
await configureCommand(defaultRuntime);
|
||||
return;
|
||||
}
|
||||
|
||||
if (invalid.length > 0) {
|
||||
defaultRuntime.error(
|
||||
`Invalid --section: ${invalid.join(", ")}. Expected one of: ${CONFIGURE_WIZARD_SECTIONS.join(", ")}.`,
|
||||
);
|
||||
defaultRuntime.exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
await configureCommandWithSections(sections as never, defaultRuntime);
|
||||
const { configureCommandFromSectionsArg } = await import("../commands/configure.js");
|
||||
await configureCommandFromSectionsArg(opts.section, defaultRuntime);
|
||||
});
|
||||
|
||||
cmd
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import type { Command } from "commander";
|
||||
import {
|
||||
CONFIGURE_WIZARD_SECTIONS,
|
||||
configureCommand,
|
||||
configureCommandWithSections,
|
||||
parseConfigureWizardSections,
|
||||
configureCommandFromSectionsArg,
|
||||
} from "../../commands/configure.js";
|
||||
import { defaultRuntime } from "../../runtime.js";
|
||||
import { formatDocsLink } from "../../terminal/links.js";
|
||||
@@ -27,21 +25,7 @@ export function registerConfigureCommand(program: Command) {
|
||||
)
|
||||
.action(async (opts) => {
|
||||
await runCommandWithRuntime(defaultRuntime, async () => {
|
||||
const { sections, invalid } = parseConfigureWizardSections(opts.section);
|
||||
if (sections.length === 0) {
|
||||
await configureCommand(defaultRuntime);
|
||||
return;
|
||||
}
|
||||
|
||||
if (invalid.length > 0) {
|
||||
defaultRuntime.error(
|
||||
`Invalid --section: ${invalid.join(", ")}. Expected one of: ${CONFIGURE_WIZARD_SECTIONS.join(", ")}.`,
|
||||
);
|
||||
defaultRuntime.exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
await configureCommandWithSections(sections as never, defaultRuntime);
|
||||
await configureCommandFromSectionsArg(opts.section, defaultRuntime);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import type { WizardSection } from "./configure.shared.js";
|
||||
import { defaultRuntime } from "../runtime.js";
|
||||
import { CONFIGURE_WIZARD_SECTIONS, parseConfigureWizardSections } from "./configure.shared.js";
|
||||
import { runConfigureWizard } from "./configure.wizard.js";
|
||||
|
||||
export async function configureCommand(runtime: RuntimeEnv = defaultRuntime) {
|
||||
@@ -13,3 +14,24 @@ export async function configureCommandWithSections(
|
||||
) {
|
||||
await runConfigureWizard({ command: "configure", sections }, runtime);
|
||||
}
|
||||
|
||||
export async function configureCommandFromSectionsArg(
|
||||
rawSections: unknown,
|
||||
runtime: RuntimeEnv = defaultRuntime,
|
||||
): Promise<void> {
|
||||
const { sections, invalid } = parseConfigureWizardSections(rawSections);
|
||||
if (sections.length === 0) {
|
||||
await configureCommand(runtime);
|
||||
return;
|
||||
}
|
||||
|
||||
if (invalid.length > 0) {
|
||||
runtime.error(
|
||||
`Invalid --section: ${invalid.join(", ")}. Expected one of: ${CONFIGURE_WIZARD_SECTIONS.join(", ")}.`,
|
||||
);
|
||||
runtime.exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
await configureCommandWithSections(sections as never, runtime);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
export { configureCommand, configureCommandWithSections } from "./configure.commands.js";
|
||||
export {
|
||||
configureCommand,
|
||||
configureCommandFromSectionsArg,
|
||||
configureCommandWithSections,
|
||||
} from "./configure.commands.js";
|
||||
export { buildGatewayAuthConfig } from "./configure.gateway-auth.js";
|
||||
export {
|
||||
CONFIGURE_WIZARD_SECTIONS,
|
||||
|
||||
Reference in New Issue
Block a user