package cmd import ( "fmt" "log/slog" "os" "github.com/spf13/cobra" "go.bigb.es/cacher/internal/logging" ) var ( flagLogLevel string flagLogFormat string flagConfigPath string ) var rootCmd = &cobra.Command{ Use: "cacher", Short: "S3-backed CI cache helper for builds.sr.ht — replaces .builds/lib/ci-lib.sh", PersistentPreRunE: func(cmd *cobra.Command, args []string) error { level := slog.LevelInfo switch flagLogLevel { case "debug": level = slog.LevelDebug case "info": level = slog.LevelInfo case "warn": level = slog.LevelWarn case "error": level = slog.LevelError default: return fmt.Errorf("invalid --log-level %q (want debug|info|warn|error)", flagLogLevel) } logging.Setup(flagLogFormat, os.Stderr, level) return nil }, } func Execute() { if err := rootCmd.Execute(); err != nil { os.Exit(exitCodeFor(err)) } } func init() { rootCmd.PersistentFlags().StringVar(&flagLogLevel, "log-level", "info", "log level (debug|info|warn|error)") rootCmd.PersistentFlags().StringVar(&flagLogFormat, "log-format", "human", "log format (human|json)") rootCmd.PersistentFlags().StringVar(&flagConfigPath, "config", "", "config file (default ~/.config/cacher/config.toml)") }