mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-28 13:26:04 -06:00
refactor(cli): rely on Commander contracts (#106366)
This commit is contained in:
committed by
GitHub
parent
a03df5fd58
commit
801ec63f92
@@ -2,19 +2,9 @@
|
||||
import type { Command } from "commander";
|
||||
|
||||
export function hasExplicitOptions(command: Command, names: readonly string[]): boolean {
|
||||
if (typeof command.getOptionValueSource !== "function") {
|
||||
return false;
|
||||
}
|
||||
return names.some((name) => command.getOptionValueSource(name) === "cli");
|
||||
}
|
||||
|
||||
function getOptionSource(command: Command, name: string): string | undefined {
|
||||
if (typeof command.getOptionValueSource !== "function") {
|
||||
return undefined;
|
||||
}
|
||||
return command.getOptionValueSource(name);
|
||||
}
|
||||
|
||||
// Defensive guardrail: allow expected parent/grandparent inheritance without unbounded deep traversal.
|
||||
const MAX_INHERIT_DEPTH = 2;
|
||||
|
||||
@@ -27,7 +17,7 @@ export function inheritOptionFromParent<T = unknown>(
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const childSource = getOptionSource(command, name);
|
||||
const childSource = command.getOptionValueSource(name);
|
||||
if (childSource && childSource !== "default") {
|
||||
return undefined;
|
||||
}
|
||||
@@ -35,9 +25,9 @@ export function inheritOptionFromParent<T = unknown>(
|
||||
let depth = 0;
|
||||
let ancestor = command.parent;
|
||||
while (ancestor && depth < MAX_INHERIT_DEPTH) {
|
||||
const source = getOptionSource(ancestor, name);
|
||||
const source = ancestor.getOptionValueSource(name);
|
||||
if (source && source !== "default") {
|
||||
return ancestor.opts<Record<string, unknown>>()[name] as T | undefined;
|
||||
return ancestor.getOptionValue(name) as T | undefined;
|
||||
}
|
||||
depth += 1;
|
||||
ancestor = ancestor.parent;
|
||||
|
||||
Reference in New Issue
Block a user