-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
76 lines (66 loc) · 2.57 KB
/
main.go
File metadata and controls
76 lines (66 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// package main is the entry point for the cherry-pick tool
package main
import (
"log/slog"
"os"
configcmd "github.com/alan/cherry-picker/cmd/config"
fetchcmd "github.com/alan/cherry-picker/cmd/fetch"
"github.com/alan/cherry-picker/cmd/merge"
"github.com/alan/cherry-picker/cmd/pick"
"github.com/alan/cherry-picker/cmd/retry"
"github.com/alan/cherry-picker/cmd/status"
"github.com/alan/cherry-picker/cmd/summary"
"github.com/alan/cherry-picker/internal/config"
"github.com/spf13/cobra"
)
func main() {
var configFile string
var logLevel string
var logFormat string
rootCmd := &cobra.Command{
Use: "cherry-picker",
Short: "A CLI tool for managing cherry-picks across GitHub repositories",
Long: `cherry-picker is a CLI tool that helps manage cherry-picking commits
across GitHub repositories using a YAML configuration file to track state.`,
PersistentPreRun: func(_ *cobra.Command, _ []string) {
setupLogger(logLevel, logFormat)
},
}
// Add global flags
rootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "cherry-picks.yaml", "Configuration file path")
rootCmd.PersistentFlags().StringVarP(&logLevel, "log-level", "l", "info", "Log level (debug, info, warn, error)")
rootCmd.PersistentFlags().StringVarP(&logFormat, "log-format", "f", "text", "Log format (text, json)")
// Create commands with access to the global config file
rootCmd.AddCommand(configcmd.NewConfigCmd(&configFile, config.LoadConfig, config.SaveConfig))
rootCmd.AddCommand(fetchcmd.NewFetchCmd(&configFile, config.LoadConfig, config.SaveConfig))
rootCmd.AddCommand(status.NewStatusCmd(&configFile, config.LoadConfig, config.SaveConfig))
rootCmd.AddCommand(pick.NewPickCmd(&configFile, config.LoadConfig, config.SaveConfig))
rootCmd.AddCommand(retry.NewRetryCmd(&configFile, config.LoadConfig, config.SaveConfig))
rootCmd.AddCommand(merge.NewMergeCmd(&configFile, config.LoadConfig, config.SaveConfig))
rootCmd.AddCommand(summary.NewSummaryCmd(&configFile, config.LoadConfig))
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}
func setupLogger(level, format string) {
var logLevel slog.Level
switch level {
case "debug":
logLevel = slog.LevelDebug
case "info":
logLevel = slog.LevelInfo
case "warn":
logLevel = slog.LevelWarn
case "error":
logLevel = slog.LevelError
default:
logLevel = slog.LevelInfo
}
var handler slog.Handler
if format == "json" {
handler = slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: logLevel})
} else {
handler = slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: logLevel})
}
slog.SetDefault(slog.New(handler))
}