Skip to content

Commit 1410554

Browse files
author
wb-liuxuehuan
committed
fix(tokenplan): 优化参数处理逻辑
更新 `assign-seats` 和 `seats` 命令中的参数处理逻辑,简化对 AccountIds 和 StatusList 的检查,确保在缺少必要参数时抛出相应错误。同时,增强对 `--query-assigned` 参数的验证,确保其值为 'true' 或 'false'。此更改提高了代码的可读性和健壮性。
1 parent 1590e69 commit 1410554

2 files changed

Lines changed: 12 additions & 15 deletions

File tree

packages/cli/src/commands/tokenplan/assign-seats.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,8 @@ export default defineCommand({
8686
throw new BailianError("Missing required argument --seat-type.", ExitCode.USAGE);
8787
}
8888

89-
const accountIds = flags.accountId;
90-
const hasAccountIds =
91-
(Array.isArray(accountIds) && accountIds.length > 0) ||
92-
(typeof accountIds === "string" && accountIds.length > 0);
93-
if (!hasAccountIds) {
89+
const accountIds = flags.accountId as string[] | undefined;
90+
if (!accountIds || accountIds.length === 0) {
9491
throw new BailianError("Missing required argument --account-id.", ExitCode.USAGE);
9592
}
9693

@@ -161,11 +158,9 @@ function buildQueryParams(
161158
if (flags.namespaceId) params.NamespaceId = flags.namespaceId as string;
162159
if (flags.locale) params.Locale = flags.locale as string;
163160

164-
const accountIds = flags.accountId as string | string[] | undefined;
165-
if (Array.isArray(accountIds) && accountIds.length > 0) {
161+
const accountIds = flags.accountId as string[] | undefined;
162+
if (accountIds && accountIds.length > 0) {
166163
params.AccountIds = accountIds;
167-
} else if (typeof accountIds === "string" && accountIds.length > 0) {
168-
params.AccountIds = [accountIds];
169164
}
170165

171166
return params;

packages/cli/src/commands/tokenplan/seats.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,20 @@ function buildQueryParams(flags: GlobalFlags): Record<string, string | string[]
143143
if (flags.namespaceId) params.NamespaceId = flags.namespaceId as string;
144144
if (flags.statusListStr) params.StatusListStr = flags.statusListStr as string;
145145

146-
const status = flags.status;
147-
if (Array.isArray(status) && status.length > 0) {
148-
params.StatusList = status as string[];
149-
} else if (typeof status === "string" && status.length > 0) {
150-
params.StatusList = [status];
146+
const status = flags.status as string[] | undefined;
147+
if (status && status.length > 0) {
148+
params.StatusList = status;
151149
}
152150

153151
if (flags.seatId) params.SeatId = flags.seatId as string;
154152
if (flags.seatType) params.SeatType = flags.seatType as string;
155153

156154
if (typeof flags.queryAssigned === "string" && flags.queryAssigned.length > 0) {
157-
params.QueryAssigned = flags.queryAssigned;
155+
const val = flags.queryAssigned.toLowerCase();
156+
if (val !== "true" && val !== "false") {
157+
throw new BailianError("--query-assigned must be 'true' or 'false'.", ExitCode.USAGE);
158+
}
159+
params.QueryAssigned = val;
158160
}
159161

160162
return params;

0 commit comments

Comments
 (0)