eth-blob-indexer/cmd/flags.go

51 lines
1016 B
Go

package cmd
import (
"flag"
"log/slog"
"os"
"github.com/lmittmann/tint"
)
const (
defaultRedisAddr = "localhost:6379"
defaultRedisPassword = ""
)
var (
// Flags shared among CLI entrypoints
Flags *flag.FlagSet
RedisAddress string
RedisPassword string
LogLevel flagLevel
logLevelVar slog.LevelVar
)
func init() {
h := tint.NewHandler(os.Stderr, &tint.Options{Level: &logLevelVar})
slog.SetDefault(slog.New(h))
Flags = flag.NewFlagSet("blob-indexer", flag.ExitOnError)
Flags.StringVar(&RedisAddress, "redis-addr", defaultRedisAddr, "Address of the Redis server")
Flags.StringVar(&RedisPassword, "redis-password", defaultRedisPassword, "Password for the Redis server")
Flags.Var(&LogLevel, "log-level", "Log level (default INFO)")
}
type flagLevel struct{ slog.Level }
func (fl *flagLevel) Set(value string) error {
return fl.UnmarshalText([]byte(value))
}
func ParseFlags() {
err := Flags.Parse(os.Args[1:])
if err != nil {
panic(err)
}
logLevelVar.Set(LogLevel.Level)
}