feat: 扩展 Sub2API 成本与余额运维
This commit is contained in:
@@ -11,8 +11,9 @@ export interface RuntimeOptions {
|
||||
platform: string | null;
|
||||
pageToken: string | null;
|
||||
template: string | null;
|
||||
kind: "temp-unschedulable" | "priority";
|
||||
kind: "temp-unschedulable" | "priority" | "account-name";
|
||||
priority: number | null;
|
||||
name: string | null;
|
||||
confirm: boolean;
|
||||
full: boolean;
|
||||
raw: boolean;
|
||||
@@ -25,7 +26,7 @@ export interface RuntimeOptions {
|
||||
export function parseRuntimeOptions(args: string[]): RuntimeOptions {
|
||||
const [actionRaw = "list", ...rest] = args;
|
||||
if (!(["list", "get", "errors", "infrastructure", "apply", "delete"] as string[]).includes(actionRaw)) {
|
||||
throw new Error("runtime usage: list|get|errors|infrastructure|apply|delete [--account <name-or-id>|--accounts <selectors>] [--group <name-or-id>|--all-groups] [--platform <name>] [--page-token <token>] [--since 24h] [--tail 50000] [--template <id>] [--kind temp-unschedulable|priority] [--priority <0-1000>] [--confirm] [--target <id>] [--json|--full|--raw]");
|
||||
throw new Error("runtime usage: list|get|errors|infrastructure|apply|delete [--account <name-or-id>|--accounts <selectors>] [--group <name-or-id>|--all-groups] [--platform <name>] [--page-token <token>] [--since 24h] [--tail 50000] [--template <id>] [--kind temp-unschedulable|priority|account-name] [--priority <0-1000>|--name <account-name>] [--confirm] [--target <id>] [--json|--full|--raw]");
|
||||
}
|
||||
let account: string | null = null;
|
||||
let accounts: string[] = [];
|
||||
@@ -34,8 +35,9 @@ export function parseRuntimeOptions(args: string[]): RuntimeOptions {
|
||||
let platform: string | null = null;
|
||||
let pageToken: string | null = null;
|
||||
let template: string | null = null;
|
||||
let kind: "temp-unschedulable" | "priority" = "temp-unschedulable";
|
||||
let kind: "temp-unschedulable" | "priority" | "account-name" = "temp-unschedulable";
|
||||
let priority: number | null = null;
|
||||
let name: string | null = null;
|
||||
let confirm = false;
|
||||
let full = false;
|
||||
let raw = false;
|
||||
@@ -73,6 +75,8 @@ export function parseRuntimeOptions(args: string[]): RuntimeOptions {
|
||||
else if (arg.startsWith("--kind=")) kind = parseRuntimeKind(arg.slice("--kind=".length));
|
||||
else if (arg === "--priority") priority = parsePriority(readValue("--priority"));
|
||||
else if (arg.startsWith("--priority=")) priority = parsePriority(arg.slice("--priority=".length));
|
||||
else if (arg === "--name") name = readValue("--name");
|
||||
else if (arg.startsWith("--name=")) name = arg.slice("--name=".length).trim();
|
||||
else if (arg === "--target") targetId = readValue("--target");
|
||||
else if (arg.startsWith("--target=")) targetId = arg.slice("--target=".length).trim();
|
||||
else if (arg === "--since") since = readValue("--since");
|
||||
@@ -100,12 +104,19 @@ export function parseRuntimeOptions(args: string[]): RuntimeOptions {
|
||||
if (kind === "priority" && priority === null) throw new Error("runtime apply --kind priority requires --priority <0-1000>");
|
||||
if (kind === "priority" && template !== null) throw new Error("runtime apply --kind priority does not accept --template");
|
||||
if (kind !== "priority" && priority !== null) throw new Error("--priority requires --kind priority");
|
||||
if (kind === "account-name" && action !== "apply") throw new Error("runtime --kind account-name only supports apply");
|
||||
if (kind === "account-name" && (name === null || name.length === 0 || name.length > 256 || /[\r\n]/u.test(name))) {
|
||||
throw new Error("runtime apply --kind account-name requires --name with a supported account name");
|
||||
}
|
||||
if (kind === "account-name" && accounts.length > 0) throw new Error("runtime account-name updates exactly one --account at a time");
|
||||
if (kind === "account-name" && template !== null) throw new Error("runtime apply --kind account-name does not accept --template");
|
||||
if (kind !== "account-name" && name !== null) throw new Error("--name requires --kind account-name");
|
||||
if (action !== "apply" && template !== null) throw new Error(`runtime ${action} does not accept --template`);
|
||||
if (action !== "errors" && action !== "infrastructure" && (since !== "24h" || tail !== 50_000)) throw new Error(`runtime ${action} does not accept --since or --tail`);
|
||||
if (!/^\d+[mhd]$/u.test(since)) throw new Error("--since must use <number>m, <number>h, or <number>d");
|
||||
if (["list", "get", "errors", "infrastructure"].includes(action) && confirm) throw new Error(`runtime ${action} does not accept --confirm`);
|
||||
if ([full, raw, json].filter(Boolean).length > 1) throw new Error("use only one of --json, --full, or --raw");
|
||||
return { action, account, accounts, group, allGroups, platform, pageToken, template, kind, priority, confirm, full, raw, json, since, tail, targetId };
|
||||
return { action, account, accounts, group, allGroups, platform, pageToken, template, kind, priority, name, confirm, full, raw, json, since, tail, targetId };
|
||||
}
|
||||
|
||||
function parseAccountSelectors(value: string): string[] {
|
||||
@@ -116,8 +127,8 @@ function parseAccountSelectors(value: string): string[] {
|
||||
return selectors;
|
||||
}
|
||||
|
||||
function parseRuntimeKind(value: string): "temp-unschedulable" | "priority" {
|
||||
if (value !== "temp-unschedulable" && value !== "priority") throw new Error("--kind must be temp-unschedulable or priority");
|
||||
function parseRuntimeKind(value: string): "temp-unschedulable" | "priority" | "account-name" {
|
||||
if (value !== "temp-unschedulable" && value !== "priority" && value !== "account-name") throw new Error("--kind must be temp-unschedulable, priority, or account-name");
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user