UNPKG

polyv-live-cli

Version:

CLI tool for managing PolyV live streaming services.

132 lines (127 loc) β€’ 4.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateOutputFormat = validateOutputFormat; exports.registerSetupCommand = registerSetupCommand; const setup_handler_1 = require("../handlers/setup.handler"); const manager_1 = require("../config/manager"); const auth_adapter_1 = require("../config/auth-adapter"); const errors_1 = require("../utils/errors"); const DEFAULT_TIMEOUT_MS = 30000; async function loadAuthAndServiceConfig(parentOptions) { const authResult = auth_adapter_1.authAdapter.tryGetAuthConfig(parentOptions); if (!authResult) { throw new Error(auth_adapter_1.authAdapter.getStatusMessage(parentOptions)); } let configResult; try { configResult = await manager_1.configManager.load({ cliOptions: parentOptions, }); } catch (error) { if (error instanceof Error && error.message.includes('Auth configuration is incomplete')) { configResult = { config: { baseUrl: 'https://api.polyv.net', timeout: DEFAULT_TIMEOUT_MS, debug: false, }, }; } else { throw error; } } const serviceConfig = { baseUrl: configResult.config.baseUrl, timeout: configResult.config.timeout, debug: configResult.config.debug, }; const isVerbose = !!parentOptions['verbose']; if (isVerbose) { console.log(`πŸ” Authentication Source: ${authResult.source}`); if (authResult.accountName) { console.log(`πŸ‘€ Account: ${authResult.accountName}`); } console.log(''); } return { authConfig: authResult.config, serviceConfig, isVerbose, }; } function validateOutputFormat(value) { if (!['table', 'json'].includes(value)) { throw new Error('Invalid output format. Must be "table" or "json"'); } return value; } function registerSetupCommand(program) { const setupCmd = program .command('setup [scene]') .description('Initialize a scene with predefined resources') .option('-l, --list', 'List available scenes') .option('--detailed', 'Show detailed scene information (with --list)') .option('--dry-run', 'Preview what would be created without making changes') .option('-o, --output <format>', 'Output format (table|json)', validateOutputFormat, 'table') .action(async (scene, options) => { try { const parentOptions = program.opts(); const { authConfig, serviceConfig } = await loadAuthAndServiceConfig(parentOptions); const setupHandler = new setup_handler_1.SetupHandler(authConfig, serviceConfig); if (options.list) { if (options.detailed) { await setupHandler.listScenesDetailed({ output: options.output ?? 'table', detailed: true, }); } else { await setupHandler.listScenes({ output: options.output ?? 'table', detailed: false, }); } return; } if (!scene) { console.error('Error: Scene name is required.'); console.error(''); console.error('Usage: polyv-live-cli setup <scene-name>'); console.error(' polyv-live-cli setup --list'); console.error(''); console.error('Example:'); console.error(' polyv-live-cli setup e-commerce'); console.error(' polyv-live-cli setup --list'); process.exit(1); } await setupHandler.setup({ scene, output: options.output ?? 'table', dryRun: options.dryRun ?? false, }); } catch (error) { (0, errors_1.logError)(error instanceof Error ? error : new Error(String(error))); process.exit(1); } }); setupCmd.addHelpText('after', ` Examples: # Initialize e-commerce scene $ polyv-live-cli setup e-commerce # List available scenes $ polyv-live-cli setup --list # Preview what would be created (dry run) $ polyv-live-cli setup e-commerce --dry-run # Get detailed scene information $ polyv-live-cli setup --list --detailed Available Scenes: e-commerce - η”΅ε•†η›΄ζ’­εœΊζ™― (ι’‘ι“γ€ε•†ε“γ€δΌ˜ζƒ εˆΈ) Custom Scenes: You can create custom scenes in ~/.polyv/scenes/ directory. See documentation for scene configuration format. `); } //# sourceMappingURL=setup.commands.js.map