UNPKG

polyv-live-cli

Version:

CLI tool for managing PolyV live streaming services.

139 lines 6.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.registerMonitorCommands = registerMonitorCommands; const monitor_handler_1 = require("../handlers/monitor.handler"); const monitor_service_1 = require("../services/monitor-service"); const errors_1 = require("../utils/errors"); const api_command_1 = require("../utils/api-command"); const formatter_1 = require("../utils/formatter"); function displayApiResult(data, output = 'table') { if (output === 'json') { console.log((0, formatter_1.formatJSON)(data)); return; } if (!Array.isArray(data) || data.length === 0 || typeof data[0] !== 'object') { console.log((0, formatter_1.formatJSON)(data)); return; } const headers = Object.keys(data[0]); const rows = data.map((item) => headers.map((header) => { const value = item?.[header]; return typeof value === 'object' && value !== null ? JSON.stringify(value) : String(value ?? ''); })); console.log((0, formatter_1.formatTable)({ headers, data: rows })); } function resolveOutputOption(options, command) { const parentOutputSource = command?.parent?.getOptionValueSource('output'); const commandOutputSource = command?.getOptionValueSource('output'); if (parentOutputSource && parentOutputSource !== 'default' && (!commandOutputSource || commandOutputSource === 'default')) { return String(command?.parent?.getOptionValue('output') ?? options.output ?? 'table'); } return String(options.output ?? 'table'); } function registerMonitorCommands(program) { const monitorCommand = program .command('monitor') .description('Start live streaming monitoring dashboard') .option('-r, --refresh <seconds>', 'Refresh interval in seconds', '5') .option('-l, --layout <layout>', 'Dashboard layout (default, compact, single)', 'default') .option('-t, --theme <theme>', 'Color theme (default, dark)', 'default') .option('-c, --config <path>', 'Configuration file path') .option('-o, --output <format>', 'Output format for status commands', 'table') .option('-v, --verbose', 'Enable verbose logging', false) .option('-d, --debug', 'Enable debug mode', false) .action(async (options) => { const handler = new monitor_handler_1.MonitorHandler(); await handler.startMonitoring(options); }); monitorCommand .command('tencent-stream-info-list') .description('List Tencent stream monitoring info') .requiredOption('--channel-id <id>', 'channel ID') .option('-o, --output <format>', 'output format (table|json)', api_command_1.validateOutputFormat, 'table') .action(async (options, command) => { try { const { authConfig, serviceConfig } = await (0, api_command_1.loadApiCommandConfig)((0, api_command_1.commandParentOptions)(program)); const service = new monitor_service_1.MonitorServiceSdk(authConfig, serviceConfig); displayApiResult(await service.listTencentStreamInfo((0, api_command_1.apiParams)(options)), resolveOutputOption(options, command)); } catch (error) { (0, errors_1.logError)(error instanceof Error ? error : new Error(String(error))); process.exit(1); } }); monitorCommand .command('stream-info-list') .description('List V4 channel realtime stream monitoring info') .requiredOption('--channel-id <id>', 'channel ID') .option('--start-time <timestamp>', 'start timestamp') .option('--end-time <timestamp>', 'end timestamp') .option('-o, --output <format>', 'output format (table|json)', api_command_1.validateOutputFormat, 'table') .action(async (options, command) => { try { const { authConfig, serviceConfig } = await (0, api_command_1.loadApiCommandConfig)((0, api_command_1.commandParentOptions)(program)); const service = new monitor_service_1.MonitorServiceSdk(authConfig, serviceConfig); displayApiResult(await service.listMonitorStreamInfo((0, api_command_1.apiParams)(options)), resolveOutputOption(options, command)); } catch (error) { (0, errors_1.logError)(error instanceof Error ? error : new Error(String(error))); process.exit(1); } }); monitorCommand .command('status') .description('Show monitoring dashboard status') .option('-o, --output <format>', 'Output format (table, json)', 'table') .action(async (options, command) => { const handler = new monitor_handler_1.MonitorHandler(); await handler.showStatus({ ...options, output: resolveOutputOption(options, command) }); }); monitorCommand .command('config') .description('Manage monitoring configuration') .option('-o, --output <format>', 'Output format (table, json)', 'table') .action(async (options, command) => { const handler = new monitor_handler_1.MonitorHandler(); await handler.showConfig({ ...options, output: resolveOutputOption(options, command) }); }); monitorCommand .command('layouts') .description('List available dashboard layouts') .option('-o, --output <format>', 'Output format (table, json)', 'table') .action(async (options, command) => { const handler = new monitor_handler_1.MonitorHandler(); await handler.listLayouts({ ...options, output: resolveOutputOption(options, command) }); }); monitorCommand .command('themes') .description('List available themes') .option('-o, --output <format>', 'Output format (table, json)', 'table') .action(async (options, command) => { const handler = new monitor_handler_1.MonitorHandler(); await handler.listThemes({ ...options, output: resolveOutputOption(options, command) }); }); monitorCommand .command('test') .description('Test monitoring dashboard compatibility') .option('-o, --output <format>', 'Output format (table, json)', 'table') .action(async (options, command) => { const handler = new monitor_handler_1.MonitorHandler(); await handler.testCompatibility({ ...options, output: resolveOutputOption(options, command) }); }); monitorCommand .command('export <filepath>') .description('Export monitoring configuration') .action(async (filepath) => { const handler = new monitor_handler_1.MonitorHandler(); await handler.exportConfig(filepath); }); monitorCommand .command('import <filepath>') .description('Import monitoring configuration') .action(async (filepath) => { const handler = new monitor_handler_1.MonitorHandler(); await handler.importConfig(filepath); }); } //# sourceMappingURL=monitor.commands.js.map