mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-30 03:11:10 +00:00
36 lines
850 B
TypeScript
36 lines
850 B
TypeScript
export const FLAG_TERMINATOR = "--";
|
|
|
|
const ROOT_BOOLEAN_FLAGS = new Set(["--dev", "--no-color"]);
|
|
const ROOT_VALUE_FLAGS = new Set(["--profile", "--log-level", "--container"]);
|
|
|
|
export function isValueToken(arg: string | undefined): boolean {
|
|
if (!arg || arg === FLAG_TERMINATOR) {
|
|
return false;
|
|
}
|
|
if (!arg.startsWith("-")) {
|
|
return true;
|
|
}
|
|
return /^-\d+(?:\.\d+)?$/.test(arg);
|
|
}
|
|
|
|
export function consumeRootOptionToken(args: ReadonlyArray<string>, index: number): number {
|
|
const arg = args[index];
|
|
if (!arg) {
|
|
return 0;
|
|
}
|
|
if (ROOT_BOOLEAN_FLAGS.has(arg)) {
|
|
return 1;
|
|
}
|
|
if (
|
|
arg.startsWith("--profile=") ||
|
|
arg.startsWith("--log-level=") ||
|
|
arg.startsWith("--container=")
|
|
) {
|
|
return 1;
|
|
}
|
|
if (ROOT_VALUE_FLAGS.has(arg)) {
|
|
return isValueToken(args[index + 1]) ? 2 : 1;
|
|
}
|
|
return 0;
|
|
}
|