mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 15:51:22 +00:00
CLI: resolve parent/subcommand option collisions (#18725)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: b7e51cf909
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,20 @@ import type { Command } from "commander";
|
||||
import { danger } from "../globals.js";
|
||||
import { defaultRuntime } from "../runtime.js";
|
||||
import { callBrowserRequest, type BrowserParentOpts } from "./browser-cli-shared.js";
|
||||
import { inheritOptionFromParent } from "./command-options.js";
|
||||
|
||||
function resolveTargetId(rawTargetId: unknown, command: Command): string | undefined {
|
||||
const local = typeof rawTargetId === "string" ? rawTargetId.trim() : "";
|
||||
if (local) {
|
||||
return local;
|
||||
}
|
||||
const inherited = inheritOptionFromParent<string>(command, "targetId");
|
||||
if (typeof inherited !== "string") {
|
||||
return undefined;
|
||||
}
|
||||
const trimmed = inherited.trim();
|
||||
return trimmed ? trimmed : undefined;
|
||||
}
|
||||
|
||||
export function registerBrowserCookiesAndStorageCommands(
|
||||
browser: Command,
|
||||
@@ -14,6 +28,7 @@ export function registerBrowserCookiesAndStorageCommands(
|
||||
.action(async (opts, cmd) => {
|
||||
const parent = parentOpts(cmd);
|
||||
const profile = parent?.browserProfile;
|
||||
const targetId = resolveTargetId(opts.targetId, cmd);
|
||||
try {
|
||||
const result = await callBrowserRequest<{ cookies?: unknown[] }>(
|
||||
parent,
|
||||
@@ -21,7 +36,7 @@ export function registerBrowserCookiesAndStorageCommands(
|
||||
method: "GET",
|
||||
path: "/cookies",
|
||||
query: {
|
||||
targetId: opts.targetId?.trim() || undefined,
|
||||
targetId,
|
||||
profile,
|
||||
},
|
||||
},
|
||||
@@ -48,6 +63,7 @@ export function registerBrowserCookiesAndStorageCommands(
|
||||
.action(async (name: string, value: string, opts, cmd) => {
|
||||
const parent = parentOpts(cmd);
|
||||
const profile = parent?.browserProfile;
|
||||
const targetId = resolveTargetId(opts.targetId, cmd);
|
||||
try {
|
||||
const result = await callBrowserRequest(
|
||||
parent,
|
||||
@@ -56,7 +72,7 @@ export function registerBrowserCookiesAndStorageCommands(
|
||||
path: "/cookies/set",
|
||||
query: profile ? { profile } : undefined,
|
||||
body: {
|
||||
targetId: opts.targetId?.trim() || undefined,
|
||||
targetId,
|
||||
cookie: { name, value, url: opts.url },
|
||||
},
|
||||
},
|
||||
@@ -80,6 +96,7 @@ export function registerBrowserCookiesAndStorageCommands(
|
||||
.action(async (opts, cmd) => {
|
||||
const parent = parentOpts(cmd);
|
||||
const profile = parent?.browserProfile;
|
||||
const targetId = resolveTargetId(opts.targetId, cmd);
|
||||
try {
|
||||
const result = await callBrowserRequest(
|
||||
parent,
|
||||
@@ -88,7 +105,7 @@ export function registerBrowserCookiesAndStorageCommands(
|
||||
path: "/cookies/clear",
|
||||
query: profile ? { profile } : undefined,
|
||||
body: {
|
||||
targetId: opts.targetId?.trim() || undefined,
|
||||
targetId,
|
||||
},
|
||||
},
|
||||
{ timeoutMs: 20000 },
|
||||
@@ -117,6 +134,7 @@ export function registerBrowserCookiesAndStorageCommands(
|
||||
.action(async (key: string | undefined, opts, cmd2) => {
|
||||
const parent = parentOpts(cmd2);
|
||||
const profile = parent?.browserProfile;
|
||||
const targetId = resolveTargetId(opts.targetId, cmd2);
|
||||
try {
|
||||
const result = await callBrowserRequest<{ values?: Record<string, string> }>(
|
||||
parent,
|
||||
@@ -125,7 +143,7 @@ export function registerBrowserCookiesAndStorageCommands(
|
||||
path: `/storage/${kind}`,
|
||||
query: {
|
||||
key: key?.trim() || undefined,
|
||||
targetId: opts.targetId?.trim() || undefined,
|
||||
targetId,
|
||||
profile,
|
||||
},
|
||||
},
|
||||
@@ -151,6 +169,7 @@ export function registerBrowserCookiesAndStorageCommands(
|
||||
.action(async (key: string, value: string, opts, cmd2) => {
|
||||
const parent = parentOpts(cmd2);
|
||||
const profile = parent?.browserProfile;
|
||||
const targetId = resolveTargetId(opts.targetId, cmd2);
|
||||
try {
|
||||
const result = await callBrowserRequest(
|
||||
parent,
|
||||
@@ -161,7 +180,7 @@ export function registerBrowserCookiesAndStorageCommands(
|
||||
body: {
|
||||
key,
|
||||
value,
|
||||
targetId: opts.targetId?.trim() || undefined,
|
||||
targetId,
|
||||
},
|
||||
},
|
||||
{ timeoutMs: 20000 },
|
||||
@@ -184,6 +203,7 @@ export function registerBrowserCookiesAndStorageCommands(
|
||||
.action(async (opts, cmd2) => {
|
||||
const parent = parentOpts(cmd2);
|
||||
const profile = parent?.browserProfile;
|
||||
const targetId = resolveTargetId(opts.targetId, cmd2);
|
||||
try {
|
||||
const result = await callBrowserRequest(
|
||||
parent,
|
||||
@@ -192,7 +212,7 @@ export function registerBrowserCookiesAndStorageCommands(
|
||||
path: `/storage/${kind}/clear`,
|
||||
query: profile ? { profile } : undefined,
|
||||
body: {
|
||||
targetId: opts.targetId?.trim() || undefined,
|
||||
targetId,
|
||||
},
|
||||
},
|
||||
{ timeoutMs: 20000 },
|
||||
|
||||
Reference in New Issue
Block a user