"use strict";
/**
 * Shared Command Helpers
 * Issue #518: DRY - Extract duplicated patterns from command files
 *
 * Provides:
 * - TOKEN_WARNING: Shared help text for --token option [SEC4-01]
 * - handleCommandError(): Unified error handler for command catch blocks
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.TOKEN_WARNING = void 0;
exports.handleCommandError = handleCommandError;
const types_1 = require("../types");
const api_client_1 = require("./api-client");
/**
 * Token option warning text [SEC4-01]
 * Shared across all commands that accept --token.
 */
exports.TOKEN_WARNING = 'Auth token (WARNING: visible in process list. Prefer CM_AUTH_TOKEN env var)';
/**
 * Unified error handler for CLI command catch blocks.
 * Prints error message to stderr and exits with appropriate code.
 *
 * @param error - Caught error (ApiError or unknown)
 */
function handleCommandError(error) {
    if (error instanceof api_client_1.ApiError) {
        console.error(`Error: ${error.message}`);
        process.exit(error.exitCode);
    }
    console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
    process.exit(types_1.ExitCode.UNEXPECTED_ERROR);
}
