mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-29 19:01:44 +00:00
refactor: share plugin setup helpers
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { consumeRootOptionToken, FLAG_TERMINATOR } from "../infra/cli-root-options.js";
|
||||
import { getPrimaryCommand } from "./argv.js";
|
||||
import { forwardConsumedCliRootOption } from "./root-option-forward.js";
|
||||
import { takeCliRootOptionValue } from "./root-option-value.js";
|
||||
|
||||
type CliContainerParseResult =
|
||||
@@ -56,14 +57,8 @@ export function parseCliContainerArgs(argv: string[]): CliContainerParseResult {
|
||||
continue;
|
||||
}
|
||||
|
||||
const consumedRootOption = consumeRootOptionToken(args, i);
|
||||
const consumedRootOption = forwardConsumedCliRootOption(args, i, out);
|
||||
if (consumedRootOption > 0) {
|
||||
for (let offset = 0; offset < consumedRootOption; offset += 1) {
|
||||
const token = args[i + offset];
|
||||
if (token !== undefined) {
|
||||
out.push(token);
|
||||
}
|
||||
}
|
||||
i += consumedRootOption - 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { consumeRootOptionToken, FLAG_TERMINATOR } from "../infra/cli-root-options.js";
|
||||
import { FLAG_TERMINATOR } from "../infra/cli-root-options.js";
|
||||
import { resolveRequiredHomeDir } from "../infra/home-dir.js";
|
||||
import { getPrimaryCommand } from "./argv.js";
|
||||
import { isValidProfileName } from "./profile-utils.js";
|
||||
import { forwardConsumedCliRootOption } from "./root-option-forward.js";
|
||||
import { takeCliRootOptionValue } from "./root-option-value.js";
|
||||
|
||||
export type CliProfileParseResult =
|
||||
@@ -65,14 +66,8 @@ export function parseCliProfileArgs(argv: string[]): CliProfileParseResult {
|
||||
continue;
|
||||
}
|
||||
|
||||
const consumedRootOption = consumeRootOptionToken(args, i);
|
||||
const consumedRootOption = forwardConsumedCliRootOption(args, i, out);
|
||||
if (consumedRootOption > 0) {
|
||||
for (let offset = 0; offset < consumedRootOption; offset += 1) {
|
||||
const token = args[i + offset];
|
||||
if (token !== undefined) {
|
||||
out.push(token);
|
||||
}
|
||||
}
|
||||
i += consumedRootOption - 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
21
src/cli/root-option-forward.ts
Normal file
21
src/cli/root-option-forward.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { consumeRootOptionToken } from "../infra/cli-root-options.js";
|
||||
|
||||
export function forwardConsumedCliRootOption(
|
||||
args: readonly string[],
|
||||
index: number,
|
||||
out: string[],
|
||||
): number {
|
||||
const consumedRootOption = consumeRootOptionToken(args, index);
|
||||
if (consumedRootOption <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (let offset = 0; offset < consumedRootOption; offset += 1) {
|
||||
const token = args[index + offset];
|
||||
if (token !== undefined) {
|
||||
out.push(token);
|
||||
}
|
||||
}
|
||||
|
||||
return consumedRootOption;
|
||||
}
|
||||
Reference in New Issue
Block a user