CLI: resolve parent/subcommand option collisions (#18725)
Merged via /review-pr -> /prepare-pr -> /merge-pr. Prepared head SHA: b7e51cf90950cdd3049ac3c7a3a949717b8ba261 Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com> Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com> Reviewed-by: @gumadeiras
This commit is contained in:
committed by
GitHub
parent
fa4f66255c
commit
985ec71c55
@@ -2,6 +2,7 @@ import type { Command } from "commander";
|
||||
import { defaultRuntime } from "../runtime.js";
|
||||
import { formatDocsLink } from "../terminal/links.js";
|
||||
import { theme } from "../terminal/theme.js";
|
||||
import { inheritOptionFromParent } from "./command-options.js";
|
||||
import { formatHelpExamples } from "./help-format.js";
|
||||
import {
|
||||
type UpdateCommandOptions,
|
||||
@@ -15,6 +16,21 @@ import { updateWizardCommand } from "./update-cli/wizard.js";
|
||||
export { updateCommand, updateStatusCommand, updateWizardCommand };
|
||||
export type { UpdateCommandOptions, UpdateStatusOptions, UpdateWizardOptions };
|
||||
|
||||
function inheritedUpdateJson(command?: Command): boolean {
|
||||
return Boolean(inheritOptionFromParent<boolean>(command, "json"));
|
||||
}
|
||||
|
||||
function inheritedUpdateTimeout(
|
||||
opts: { timeout?: unknown },
|
||||
command?: Command,
|
||||
): string | undefined {
|
||||
const timeout = opts.timeout as string | undefined;
|
||||
if (timeout) {
|
||||
return timeout;
|
||||
}
|
||||
return inheritOptionFromParent<string>(command, "timeout");
|
||||
}
|
||||
|
||||
export function registerUpdateCli(program: Command) {
|
||||
const update = program
|
||||
.command("update")
|
||||
@@ -89,10 +105,10 @@ ${theme.muted("Docs:")} ${formatDocsLink("/cli/update", "docs.openclaw.ai/cli/up
|
||||
"after",
|
||||
`\n${theme.muted("Docs:")} ${formatDocsLink("/cli/update", "docs.openclaw.ai/cli/update")}\n`,
|
||||
)
|
||||
.action(async (opts) => {
|
||||
.action(async (opts, command) => {
|
||||
try {
|
||||
await updateWizardCommand({
|
||||
timeout: opts.timeout as string | undefined,
|
||||
timeout: inheritedUpdateTimeout(opts, command),
|
||||
});
|
||||
} catch (err) {
|
||||
defaultRuntime.error(String(err));
|
||||
@@ -118,11 +134,11 @@ ${theme.muted("Docs:")} ${formatDocsLink("/cli/update", "docs.openclaw.ai/cli/up
|
||||
"Docs:",
|
||||
)} ${formatDocsLink("/cli/update", "docs.openclaw.ai/cli/update")}`,
|
||||
)
|
||||
.action(async (opts) => {
|
||||
.action(async (opts, command) => {
|
||||
try {
|
||||
await updateStatusCommand({
|
||||
json: Boolean(opts.json),
|
||||
timeout: opts.timeout as string | undefined,
|
||||
json: Boolean(opts.json) || inheritedUpdateJson(command),
|
||||
timeout: inheritedUpdateTimeout(opts, command),
|
||||
});
|
||||
} catch (err) {
|
||||
defaultRuntime.error(String(err));
|
||||
|
||||
Reference in New Issue
Block a user