fix(tokenplan): 优化参数处理逻辑

更新 `assign-seats` 和 `seats` 命令中的参数处理逻辑,简化对 AccountIds 和 StatusList 的检查,确保在缺少必要参数时抛出相应错误。同时,增强对 `--query-assigned` 参数的验证,确保其值为 'true' 或 'false'。此更改提高了代码的可读性和健壮性。
This commit is contained in:
wb-liuxuehuan
2026-06-23 18:27:12 +08:00
parent 1590e69d67
commit 14105547e8
2 changed files with 12 additions and 15 deletions
@@ -86,11 +86,8 @@ export default defineCommand({
throw new BailianError("Missing required argument --seat-type.", ExitCode.USAGE);
}
const accountIds = flags.accountId;
const hasAccountIds =
(Array.isArray(accountIds) && accountIds.length > 0) ||
(typeof accountIds === "string" && accountIds.length > 0);
if (!hasAccountIds) {
const accountIds = flags.accountId as string[] | undefined;
if (!accountIds || accountIds.length === 0) {
throw new BailianError("Missing required argument --account-id.", ExitCode.USAGE);
}
@@ -161,11 +158,9 @@ function buildQueryParams(
if (flags.namespaceId) params.NamespaceId = flags.namespaceId as string;
if (flags.locale) params.Locale = flags.locale as string;
const accountIds = flags.accountId as string | string[] | undefined;
if (Array.isArray(accountIds) && accountIds.length > 0) {
const accountIds = flags.accountId as string[] | undefined;
if (accountIds && accountIds.length > 0) {
params.AccountIds = accountIds;
} else if (typeof accountIds === "string" && accountIds.length > 0) {
params.AccountIds = [accountIds];
}
return params;
+8 -6
View File
@@ -143,18 +143,20 @@ function buildQueryParams(flags: GlobalFlags): Record<string, string | string[]
if (flags.namespaceId) params.NamespaceId = flags.namespaceId as string;
if (flags.statusListStr) params.StatusListStr = flags.statusListStr as string;
const status = flags.status;
if (Array.isArray(status) && status.length > 0) {
params.StatusList = status as string[];
} else if (typeof status === "string" && status.length > 0) {
params.StatusList = [status];
const status = flags.status as string[] | undefined;
if (status && status.length > 0) {
params.StatusList = status;
}
if (flags.seatId) params.SeatId = flags.seatId as string;
if (flags.seatType) params.SeatType = flags.seatType as string;
if (typeof flags.queryAssigned === "string" && flags.queryAssigned.length > 0) {
params.QueryAssigned = flags.queryAssigned;
const val = flags.queryAssigned.toLowerCase();
if (val !== "true" && val !== "false") {
throw new BailianError("--query-assigned must be 'true' or 'false'.", ExitCode.USAGE);
}
params.QueryAssigned = val;
}
return params;