refactor(cli): share configure section runner

This commit is contained in:
Peter Steinberger
2026-02-15 14:20:06 +00:00
parent a58088383b
commit 1a758135d8
4 changed files with 31 additions and 40 deletions

View File

@@ -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);
}

View File

@@ -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,