|
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "os" |
| 5 | + |
| 6 | + "github.com/fatih/color" |
| 7 | + "github.com/gambitier/tag-manager/pkg/config" |
| 8 | + "github.com/spf13/cobra" |
| 9 | +) |
| 10 | + |
| 11 | +var configCmd = &cobra.Command{ |
| 12 | + Use: "config", |
| 13 | + Short: "Show current configuration", |
| 14 | + Long: `Display the current tag-manager configuration including file location and package settings.`, |
| 15 | + RunE: runConfig, |
| 16 | +} |
| 17 | + |
| 18 | +func runConfig(cmd *cobra.Command, args []string) error { |
| 19 | + // Get config path |
| 20 | + configPath := config.GetConfigPath() |
| 21 | + |
| 22 | + // Check if config file exists |
| 23 | + exists := true |
| 24 | + if _, err := os.Stat(configPath); os.IsNotExist(err) { |
| 25 | + exists = false |
| 26 | + } |
| 27 | + |
| 28 | + // Display config file location |
| 29 | + color.Cyan("=== Tag Manager Configuration ===") |
| 30 | + color.White("Config file: %s", configPath) |
| 31 | + if exists { |
| 32 | + color.Green("Status: ✓ Found") |
| 33 | + } else { |
| 34 | + color.Yellow("Status: ✗ Not found (will be created on first use)") |
| 35 | + } |
| 36 | + color.White("") |
| 37 | + |
| 38 | + // Load and display configuration |
| 39 | + cfg, err := config.LoadConfig(configPath) |
| 40 | + if err != nil { |
| 41 | + if exists { |
| 42 | + color.Red("Error loading configuration: %v", err) |
| 43 | + return nil |
| 44 | + } |
| 45 | + // If file doesn't exist, show default config |
| 46 | + color.Yellow("No configuration file found. Here are the defaults:") |
| 47 | + color.White("") |
| 48 | + |
| 49 | + // Show default configuration |
| 50 | + color.Cyan("Default Tag Format: %s", config.GetDefaultConfig().Defaults.TagFormat) |
| 51 | + color.White("") |
| 52 | + color.White("Configuration will be created automatically when you:") |
| 53 | + color.White(" • Run 'tag-manager update' for the first time") |
| 54 | + color.White(" • Configure a package's tag format") |
| 55 | + return nil |
| 56 | + } |
| 57 | + |
| 58 | + // Display current configuration |
| 59 | + color.Cyan("Current Configuration:") |
| 60 | + color.White("") |
| 61 | + |
| 62 | + // Show default tag format |
| 63 | + color.Cyan("Default Tag Format: %s", cfg.Defaults.TagFormat) |
| 64 | + color.White("") |
| 65 | + |
| 66 | + // Show configured packages |
| 67 | + if len(cfg.Packages) == 0 { |
| 68 | + color.Yellow("No packages configured yet.") |
| 69 | + color.White("Packages will be configured automatically when you run 'tag-manager update'.") |
| 70 | + } else { |
| 71 | + color.Cyan("Configured Packages (%d):", len(cfg.Packages)) |
| 72 | + for modulePath, pkgConfig := range cfg.Packages { |
| 73 | + color.White("") |
| 74 | + color.White(" Package: %s", modulePath) |
| 75 | + color.White(" Tag Format: %s", pkgConfig.TagFormat) |
| 76 | + color.White(" Use Default: %t", pkgConfig.UseDefault) |
| 77 | + if pkgConfig.LastUpdated != "" { |
| 78 | + color.White(" Last Updated: %s", pkgConfig.LastUpdated) |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + return nil |
| 84 | +} |
0 commit comments