Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ skills/ # Agent Skill 定義

### 型安全性ルール

- **`as` キャスト禁止**: 実装コードで `as` を使わない。`satisfies` または設計の見直しで対応
- **`as` キャスト原則禁止**: 実装コードで `as` を使わない。`satisfies` または設計の見直しで対応
- **SDK 型バグの回避**: SDK の型定義が実際の API と異なる場合、`apiCall()` より `as` での回避を優先する
- **discriminated union**: `client.apiCall(methodName, params)` で `Record<string, unknown>` として渡す(void メソッド)
- **データ返却メソッド**: ブランチパターンで型安全に(`if (opts.teamId) { ... } else if (opts.enterpriseId) { ... }`)

Expand Down
5 changes: 3 additions & 2 deletions src/commands/users/invite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { WebClient } from "@slack/web-api";
interface UsersInviteOptions {
teamId: string;
email: string;
channelIds: [string, ...string[]];
channelIds: string;
customMessage?: string;
realName?: string;
isRestricted?: boolean;
Expand All @@ -13,10 +13,11 @@ interface UsersInviteOptions {
}

export async function executeUsersInvite(client: WebClient, opts: UsersInviteOptions) {
// SDK型定義は channel_ids: [string, ...string[]] だが、実際のAPIはカンマ区切り文字列を期待する
return await client.admin.users.invite({
team_id: opts.teamId,
email: opts.email,
channel_ids: opts.channelIds,
channel_ids: opts.channelIds as unknown as [string, ...string[]],
...(opts.customMessage !== undefined ? { custom_message: opts.customMessage } : {}),
...(opts.realName !== undefined ? { real_name: opts.realName } : {}),
...(opts.isRestricted !== undefined ? { is_restricted: opts.isRestricted } : {}),
Expand Down
40 changes: 30 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,19 @@ const discoverabilityValueParser: ValueParser<"sync", TeamDiscoverability> = {
// Global flags (parsed manually from process.argv)
// ---------------------------------------------------------------------------

const GLOBAL_FLAGS = new Set(["--json", "--plain"]);
const GLOBAL_FLAGS = new Set(["--json", "--plain", "--verbose"]);
const GLOBAL_FLAGS_WITH_VALUE = new Set(["--profile"]);

function parseGlobalFlags(argv: string[]): {
json: boolean;
plain: boolean;
verbose: boolean;
profile: string | undefined;
rest: string[];
} {
let json = false;
let plain = false;
let verbose = false;
let profile: string | undefined;
const rest: string[] = [];

Expand All @@ -149,6 +151,8 @@ function parseGlobalFlags(argv: string[]): {
json = true;
} else if (arg === "--plain") {
plain = true;
} else if (arg === "--verbose") {
verbose = true;
} else if (arg === "--profile") {
profile = argv[i + 1];
i++;
Expand All @@ -157,12 +161,13 @@ function parseGlobalFlags(argv: string[]): {
}
}

return { json, plain, profile, rest };
return { json, plain, verbose, profile, rest };
}

const globalFlags = parseGlobalFlags(process.argv.slice(2));
const jsonFlag = globalFlags.json;
const plainFlag = globalFlags.plain;
const verboseFlag = globalFlags.verbose;
const profileFlag = globalFlags.profile;

const outputFormat: OutputFormat = jsonFlag ? "json" : plainFlag ? "plain" : "table";
Expand Down Expand Up @@ -871,16 +876,10 @@ switch (config.cmd) {
}
case "users-invite": {
const client = await createSlackClient(store, profileFlag);
const inviteChannelParts = config.channelIds.split(",");
const inviteFirstChannel = inviteChannelParts[0];
if (inviteFirstChannel === undefined) {
throw new Error("--channel-ids must not be empty");
}
const inviteChannelIds: [string, ...string[]] = [inviteFirstChannel, ...inviteChannelParts.slice(1)];
await executeUsersInvite(client, {
teamId: config.teamId,
email: config.email,
channelIds: inviteChannelIds,
channelIds: config.channelIds,
customMessage: config.customMessage,
realName: config.realName,
isRestricted: config.isRestricted,
Expand Down Expand Up @@ -1506,4 +1505,25 @@ switch (config.cmd) {
}
}

main();
main().catch((err) => {
if (verboseFlag) {
throw err;
}
if (err.code === "slack_webapi_platform_error" && err.data) {
console.error(`Slack API error: ${err.data.error}`);
if (err.data.needed) {
console.error(` needed scope: ${err.data.needed}`);
}
if (err.data.provided) {
console.error(` provided scopes: ${err.data.provided}`);
}
if (err.data.response_metadata?.messages) {
for (const msg of err.data.response_metadata.messages) {
console.error(` ${msg}`);
}
}
} else {
console.error(`Error: ${err.message ?? err}`);
}
process.exit(1);
});
Loading