import { Command } from 'commander'; export interface CommonOptions { debug?: boolean; logToFile?: boolean; logLevel?: string; verbose?: boolean; } export interface DownloadOptions extends CommonOptions { outputDir?: string; overwrite?: boolean; concurrent?: number; count?: number; all?: boolean; } export interface OutputOptions extends CommonOptions { output?: string; pretty?: boolean; } // Common option definitions export const COMMON_DEBUG_OPTIONS = [ ['--debug', 'Enable debug logging', false], ['--log-to-file', 'Save logs to file', false], ['--log-level ', 'Set log level (error, warn, info, debug, trace)', 'info'] ] as const; export const COMMON_VERBOSE_OPTIONS = [ ['--verbose', 'Show detailed progress information', false] ] as const; export const COMMON_OUTPUT_OPTIONS = [ ['-o, --output ', 'Output file path'], ['--pretty', 'Pretty print output (default: true)', true] ] as const; export const COMMON_DOWNLOAD_OPTIONS = [ ['-o, --output-dir ', 'Output directory for downloaded files', './downloads'], ['--overwrite', 'Overwrite existing files', false], ['--concurrent ', 'Maximum concurrent downloads', '3'] ] as const; export const COMMON_COUNT_OPTIONS = [ ['-n, --count ', 'Number of items to process', '10'], ['--all', 'Process all available items', false] ] as const; export const COMMON_MONITOR_OPTIONS = [ ['--monitor', 'Monitor feed changes over time', false], ['--iterations ', 'Number of monitoring iterations', '10'], ['--interval ', 'Interval between fetches in seconds', '10'] ] as const; export const COMMON_CHART_OPTIONS = [ ['--chart', 'Generate charts from monitoring data', false], ['--data-dir ', 'Directory containing feed-*.json files', './feed-monitor-results'], ['--chart-output ', 'Output directory for chart files', './feed-monitor-results'] ] as const; // Helper functions to add common options to commands export function addDebugOptions(command: Command): Command { COMMON_DEBUG_OPTIONS.forEach(([option, description, defaultValue]) => { command.option(option, description, defaultValue); }); return command; } export function addVerboseOptions(command: Command): Command { COMMON_VERBOSE_OPTIONS.forEach(([option, description, defaultValue]) => { command.option(option, description, defaultValue); }); return command; } export function addOutputOptions(command: Command): Command { COMMON_OUTPUT_OPTIONS.forEach(([option, description, defaultValue]) => { command.option(option, description, defaultValue); }); return command; } export function addDownloadOptions(command: Command): Command { COMMON_DOWNLOAD_OPTIONS.forEach(([option, description, defaultValue]) => { command.option(option, description, defaultValue); }); return command; } export function addCountOptions(command: Command): Command { COMMON_COUNT_OPTIONS.forEach(([option, description, defaultValue]) => { command.option(option, description, defaultValue); }); return command; } export function addMonitorOptions(command: Command): Command { COMMON_MONITOR_OPTIONS.forEach(([option, description, defaultValue]) => { command.option(option, description, defaultValue); }); return command; } export function addChartOptions(command: Command): Command { COMMON_CHART_OPTIONS.forEach(([option, description, defaultValue]) => { command.option(option, description, defaultValue); }); return command; } // Combined option sets for common use cases export function addCommonOptions(command: Command): Command { return addDebugOptions(addVerboseOptions(command)); } export function addDownloadCommonOptions(command: Command): Command { return addCommonOptions(addDownloadOptions(addCountOptions(command))); } export function addFeedOptions(command: Command): Command { command .option('-c, --cookies ', 'Cookies string for authentication'); return addMonitorOptions(addChartOptions(addOutputOptions(command))); } export function addDownloadFeedOptions(command: Command): Command { command .option('-c, --cookies ', 'Cookies string for authentication'); return addDownloadCommonOptions(command); } export function addDownloadUrlOptions(command: Command): Command { // Single video download is simple, doesn't need debug options command .option('-u, --url ', 'Video URL to download') .option('-t, --title ', 'Video title for filename') .option('-o, --output-dir <dir>', 'Output directory for downloaded video', './downloads') .option('--overwrite', 'Overwrite existing files', false); return command; } export function addDownloadLocalOptions(command: Command): Command { addDownloadCommonOptions(command); command .argument('<feed-file>', 'Path to the local feed.json file') .option('--list', 'List posts in the feed without downloading', false); return command; } export function addConfigOptions(command: Command): Command { // Config commands don't need debug options - they're simple operations return command; }