|
| 1 | +// Package config provides configuration management for the OBS Random Videos application. |
| 2 | +// It handles parsing command-line flags and maintaining application settings. |
| 3 | +package config |
| 4 | + |
| 5 | +import ( |
| 6 | + "flag" |
| 7 | + "os" |
| 8 | +) |
| 9 | + |
| 10 | +// Config holds the application configuration |
| 11 | +type Config struct { |
| 12 | + // OutputFileName is the name of the generated HTML file |
| 13 | + OutputFileName string |
| 14 | + // Version is the application version |
| 15 | + Version string |
| 16 | + // MaxFileSize is the maximum file size to consider (in bytes, 0 = no limit) |
| 17 | + MaxFileSize int64 |
| 18 | + // ConcurrentScans is the number of concurrent goroutines for directory scanning |
| 19 | + ConcurrentScans int |
| 20 | + // Directory is the directory to scan for media files |
| 21 | + Directory string |
| 22 | + // Recursive determines if subdirectories should be scanned |
| 23 | + Recursive bool |
| 24 | + // Verbose enables verbose output |
| 25 | + Verbose bool |
| 26 | + // AutoSanitize determines if file names should be automatically sanitized |
| 27 | + AutoSanitize bool |
| 28 | +} |
| 29 | + |
| 30 | +// Default returns a Config with default values |
| 31 | +func Default(version string) *Config { |
| 32 | + return &Config{ |
| 33 | + OutputFileName: "obs-random-videos.html", |
| 34 | + Version: version, |
| 35 | + MaxFileSize: 0, // No limit by default |
| 36 | + ConcurrentScans: 4, |
| 37 | + Directory: ".", |
| 38 | + Recursive: true, |
| 39 | + Verbose: false, |
| 40 | + AutoSanitize: false, |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +// ParseFlags parses command line flags and returns a Config |
| 45 | +func ParseFlags(version string) *Config { |
| 46 | + cfg := Default(version) |
| 47 | + |
| 48 | + flag.StringVar(&cfg.Directory, "dir", cfg.Directory, "Directory to scan for media files") |
| 49 | + flag.StringVar(&cfg.OutputFileName, "output", cfg.OutputFileName, "Output HTML filename") |
| 50 | + flag.BoolVar(&cfg.Recursive, "recursive", cfg.Recursive, "Scan subdirectories") |
| 51 | + flag.BoolVar(&cfg.Verbose, "verbose", cfg.Verbose, "Verbose output") |
| 52 | + flag.BoolVar(&cfg.AutoSanitize, "sanitize", cfg.AutoSanitize, "Automatically sanitize problematic file names") |
| 53 | + flag.Int64Var(&cfg.MaxFileSize, "max-size", cfg.MaxFileSize, "Maximum file size in bytes (0 = no limit)") |
| 54 | + flag.IntVar(&cfg.ConcurrentScans, "concurrent", cfg.ConcurrentScans, "Number of concurrent file scanners") |
| 55 | + |
| 56 | + // Check for DEBUG environment variable |
| 57 | + if os.Getenv("DEBUG") != "" { |
| 58 | + cfg.Verbose = true |
| 59 | + } |
| 60 | + |
| 61 | + flag.Parse() |
| 62 | + |
| 63 | + return cfg |
| 64 | +} |
0 commit comments