Files
openclaw/src/cli/command-path-matches.ts
2026-04-06 14:16:03 +01:00

32 lines
890 B
TypeScript

export type CommandPathMatchRule =
| readonly string[]
| {
pattern: readonly string[];
exact?: boolean;
};
export function matchesCommandPath(
commandPath: string[],
pattern: readonly string[],
params?: { exact?: boolean },
): boolean {
if (pattern.some((segment, index) => commandPath[index] !== segment)) {
return false;
}
return !params?.exact || commandPath.length === pattern.length;
}
export function matchesCommandPathRule(commandPath: string[], rule: CommandPathMatchRule): boolean {
if (Array.isArray(rule)) {
return matchesCommandPath(commandPath, rule);
}
return matchesCommandPath(commandPath, rule.pattern, { exact: rule.exact });
}
export function matchesAnyCommandPath(
commandPath: string[],
rules: readonly CommandPathMatchRule[],
): boolean {
return rules.some((rule) => matchesCommandPathRule(commandPath, rule));
}