Account Command (whoami)
Relevant source files
The following files were used as context for generating this wiki page:
The whoami command is a core utility within the Recoup CLI designed to identify and verify the currently authenticated account. It serves as the primary verification step for users to ensure their environment is correctly configured with a valid API key before executing more complex operations like artist management or content creation.
This command functions as a thin wrapper around a specific REST API endpoint, retrieving the account's unique identifier and presenting it to the user in either a human-readable or machine-readable format.
Sources: src/commands/whoami.ts, README.md:23-28, CLAUDE.md:20
Architecture and Command Logic
The whoami command is implemented using the commander library. It is registered as a top-level command in the CLI entry point and follows a standard execution pattern: authenticating via an environment variable, making a GET request to the Recoup API, and formatting the output.
Data Flow
The following sequence diagram illustrates the interaction between the user, the CLI command logic, the internal HTTP client, and the remote Recoup API.
Implementation Details
The command logic is encapsulated in a single action handler that utilizes the internal get utility for network requests.
- Endpoint: The command hits the
/api/accounts/idendpoint. - Authentication: It relies on the
RECOUP_API_KEYenvironment variable, which the HTTP client automatically injects into thex-api-keyheader. - Error Handling: If the API request fails (e.g., 401 Unauthorized), the command catches the error and utilizes a centralized
printErrorutility to display the message and exit with a non-zero status code.
Sources: src/commands/whoami.ts:10-21, CLAUDE.md:14-15, __tests__/commands/whoami.test.ts:52-59
Configuration and Options
The whoami command supports standard CLI options and relies on specific environment variables for successful execution.
CLI Options
| Option | Description | Result |
|---|---|---|
--json | Output as JSON | Prints the full API response object formatted with 2-space indentation. |
--help | Show help | Displays description and available options. |
Sources: src/commands/whoami.ts:7-9, README.md:26-27
Environment Variables
| Variable | Required | Description |
|---|---|---|
RECOUP_API_KEY | Yes | The authenticated API key obtained from the Developer Dashboard. |
RECOUP_API_URL | No | Overrides the default API base URL (https://recoup-api.vercel.app). |
Sources: README.md:57-61, CLAUDE.md:14-15, 24-25
Integration with CLI Entrypoint
The whoamiCommand is exported and added to the main program instance in the binary entry point. This ensures it is available as a subcommand of the recoup tool.
// src/bin.ts
import { whoamiCommand } from "./commands/whoami.js";
// ...
const program = new Command();
program.name("recoup");
program.addCommand(whoamiCommand);
Sources: src/bin.ts:1-24
Output Formats
The command provides two distinct output styles based on user input:
Standard Output
By default, the command prints only the raw accountId string.
abc-123
Sources: src/commands/whoami.ts:14-15, __tests__/commands/whoami.test.ts:31-41
JSON Output
When the --json flag is provided, the command utilizes the printJson utility to output the complete response body.
{
"status": "success",
"accountId": "abc-123"
}
Sources: src/commands/whoami.ts:11-13, __tests__/commands/whoami.test.ts:43-51, src/output.ts:10-15
Summary
The whoami command is a vital diagnostic tool in the Recoup CLI. By interfacing with the /api/accounts/id endpoint, it provides a simple mechanism for users to verify their authentication status and retrieve their account identifier, supporting both interactive terminal use and automated scripting through its JSON output mode.