Skip to content

Commit 5379bad

Browse files
committed
feat: add config command to display current configuration and enhance Makefile targets
1 parent 5a60156 commit 5379bad

File tree

4 files changed

+119
-10
lines changed

4 files changed

+119
-10
lines changed

Makefile

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LDFLAGS=-ldflags "-s -w"
1212
.PHONY: all build clean run list test help
1313

1414
# Default target
15-
all: build
15+
.DEFAULT_GOAL := help
1616

1717
# Build the application
1818
build:
@@ -27,10 +27,20 @@ run: build
2727
@$(BUILD_DIR)/$(BINARY_NAME) update $(ARGS)
2828

2929
# List discovered packages
30-
list: build
30+
list:
3131
@echo "Discovering Go packages..."
3232
@$(BUILD_DIR)/$(BINARY_NAME) list
3333

34+
# List packages with verbose output
35+
list-verbose: build
36+
@echo "Discovering Go packages (verbose)..."
37+
@$(BUILD_DIR)/$(BINARY_NAME) list --verbose
38+
39+
# Show current configuration
40+
config:
41+
@echo "Showing current configuration..."
42+
@$(BUILD_DIR)/$(BINARY_NAME) config
43+
3444
# Clean build artifacts
3545
clean:
3646
@echo "Cleaning build artifacts..."
@@ -53,15 +63,19 @@ test:
5363
# Show help
5464
help:
5565
@echo "Available targets:"
56-
@echo " build - Build the application"
57-
@echo " run - Build and run the application (update command)"
58-
@echo " list - Build and list discovered packages"
59-
@echo " clean - Clean build artifacts"
60-
@echo " deps - Install dependencies"
61-
@echo " test - Run tests"
62-
@echo " help - Show this help message"
66+
@echo " build - Build the application"
67+
@echo " run - Build and run the application (update command)"
68+
@echo " list - Build and list discovered packages"
69+
@echo " list-verbose - Build and list packages with full details"
70+
@echo " config - Show current configuration"
71+
@echo " clean - Clean build artifacts"
72+
@echo " deps - Install dependencies"
73+
@echo " test - Run tests"
74+
@echo " help - Show this help message"
6375
@echo ""
6476
@echo "Usage examples:"
6577
@echo " make run # Interactive tag update"
6678
@echo " make list # List discovered packages"
67-
@echo " make run ARGS=\"\" # Same as make run"
79+
@echo " make list-verbose # List with full details"
80+
@echo " make config # Show current configuration"
81+
@echo " make run ARGS=\"\" # Same as make run"

cmd/config.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
}

cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ func init() {
2727
// Add subcommands
2828
rootCmd.AddCommand(updateCmd)
2929
rootCmd.AddCommand(listCmd)
30+
rootCmd.AddCommand(configCmd)
3031
}

pkg/config/config.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ func GetConfigPath() string {
101101
return filepath.Join(homeDir, ".tag-manager.yaml")
102102
}
103103

104+
// GetDefaultConfig returns the default configuration
105+
func GetDefaultConfig() *Config {
106+
return &Config{
107+
Packages: make(map[string]PackageConfig),
108+
Defaults: DefaultConfig{
109+
TagFormat: "{package-name}/v{major}.{minor}.{patch}",
110+
},
111+
}
112+
}
113+
104114
// GetPackageConfig returns configuration for a specific package
105115
func (c *Config) GetPackageConfig(modulePath string) PackageConfig {
106116
if pkg, exists := c.Packages[modulePath]; exists {

0 commit comments

Comments
 (0)