mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-13 08:10:43 +00:00
fix(cli): preserve lazy command parent flags
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { Command } from "commander";
|
||||
import { reparseProgramFromActionArgs } from "./action-reparse.js";
|
||||
import { removeCommandByName } from "./command-tree.js";
|
||||
import { resolveCommandOptionArgs } from "./helpers.js";
|
||||
|
||||
type RegisterLazyCommandParams = {
|
||||
program: Command;
|
||||
@@ -14,25 +15,6 @@ type RegisterLazyCommandParams = {
|
||||
register: () => Promise<void> | void;
|
||||
};
|
||||
|
||||
function resolvePlaceholderOptionArgs(command: Command): string[] {
|
||||
const out: string[] = [];
|
||||
for (const option of command.options) {
|
||||
const value = command.getOptionValue(option.attributeName());
|
||||
if (value === undefined || value === false) {
|
||||
continue;
|
||||
}
|
||||
const flag = option.long ?? option.short;
|
||||
if (!flag) {
|
||||
continue;
|
||||
}
|
||||
out.push(flag);
|
||||
if (value !== true) {
|
||||
out.push(String(value));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
export function registerLazyCommand({
|
||||
program,
|
||||
name,
|
||||
@@ -51,7 +33,7 @@ export function registerLazyCommand({
|
||||
const actionCommand = actionArgs.at(-1) as (Command & { args?: string[] }) | undefined;
|
||||
if (actionCommand) {
|
||||
actionCommand.args = [
|
||||
...resolvePlaceholderOptionArgs(actionCommand),
|
||||
...resolveCommandOptionArgs(actionCommand),
|
||||
...(actionCommand.args ?? []),
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user