Fix architecture review findings and align CLI metadata

This commit is contained in:
gitea committed 2026-10-17 20:17:06 +08:00
1 parent 780a4ba9c0
commit 50e4e492b4
83 files changed
+966 -792

No files matched your search

+8 -8
View File
@@ -1,6 +1,6 @@
import type { CorpConfig } from "../../core/config/types.js";
import type { createSealClient } from "../../core/http/factory.js";
import { confirmationRequired } from "../errors.js";
import { confirmationRequired, usageError } from "../../core/errors.js";
import { runCapability } from "../helpers.js";
import { booleanOption, parseDelegationExpireHours, stringOption } from "../parser.js";
import { outputOptions } from "../printer.js";
@@ -16,7 +16,7 @@ export async function handleUsersCommand(
if (action === "create") {
const name = stringOption(args.options.name) ?? maybeName;
const phone = stringOption(args.options.phone);
if (!name || !phone) throw new Error("Usage: seal-use users create --name <name> --phone <phone> [--dept <deptId>]");
if (!name || !phone) throw usageError("Usage: seal-use users create --name <name> --phone <phone> [--dept <deptId>]");
const deptId = stringOption(args.options.dept) ?? stringOption(args.options.departmentId);
const departmentIds = deptId ? [deptId] : undefined;
await runCapability("sealUserCreate", client, corp, { name, phone, departmentIds }, outputOptions(args.options));
@@ -25,7 +25,7 @@ export async function handleUsersCommand(
if (action === "reset-password") {
const userId = maybeName ?? stringOption(args.options.userId);
if (!userId) throw new Error("Usage: seal-use users reset-password <userId> --yes");
if (!userId) throw usageError("Usage: seal-use users reset-password <userId> --yes");
const confirmed = booleanOption(args.options.yes) === true || booleanOption(args.options.confirm) === true;
if (!confirmed) {
throw confirmationRequired(
@@ -45,14 +45,14 @@ export async function handleUsersCommand(
if (action === "get") {
const userId = maybeName ?? stringOption(args.options.userId);
if (!userId) throw new Error("Usage: seal-use users get <userId>");
if (!userId) throw usageError("Usage: seal-use users get <userId>");
await runCapability("sealUserGet", client, corp, { userId }, outputOptions(args.options));
return;
}
if (action === "delete") {
const userId = maybeName ?? stringOption(args.options.userId);
if (!userId) throw new Error("Usage: seal-use users delete <userId> --yes");
if (!userId) throw usageError("Usage: seal-use users delete <userId> --yes");
const confirmed = booleanOption(args.options.yes) === true || booleanOption(args.options.confirm) === true;
if (!confirmed) {
throw confirmationRequired(
@@ -66,14 +66,14 @@ export async function handleUsersCommand(
if (action === "activate") {
const userId = maybeName ?? stringOption(args.options.userId);
if (!userId) throw new Error("Usage: seal-use users activate <userId>");
if (!userId) throw usageError("Usage: seal-use users activate <userId>");
await runCapability("sealUserActivate", client, corp, { userId }, outputOptions(args.options));
return;
}
if (action === "delegation" || action === "impersonate") {
const userIdOrPhone = maybeName ?? stringOption(args.options.userId) ?? stringOption(args.options.phone);
if (!userIdOrPhone) throw new Error("Usage: seal-use users delegation <userIdOrPhone> [--note <note>] [--expire <duration>]");
if (!userIdOrPhone) throw usageError("Usage: seal-use users delegation <userIdOrPhone> [--note <note>] [--expire <duration>]");
const note = stringOption(args.options.note);
const expireOption = args.options.expire ?? args.options["expires-in"] ?? args.options.expiresIn;
const expiresInHours = parseDelegationExpireHours(expireOption, 24);
@@ -87,5 +87,5 @@ export async function handleUsersCommand(
return;
}
throw new Error(`Unknown users command: ${action ?? ""}. Run 'seal-use help' for available commands.`);
throw usageError(`Unknown users command: ${action ?? ""}. Run 'seal-use help' for available commands.`);
}