cmd/searchix-web/check-config.go (view raw)
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 | package main import ( "errors" "fmt" "strings" "github.com/Southclaws/fault" "github.com/pelletier/go-toml/v2" "alin.ovh/searchix/internal/config" ) type CheckConfig struct{} func (*CheckConfig) Execute(_ []string) error { err := config.Load(string(globalOptions.Config), &config.Config{}) if err != nil { var details *toml.StrictMissingError if errors.As(err, &details) { return fmt.Errorf("%s", strings.ReplaceAll(details.String(), "missing", "unknown")) } return fault.Wrap(err) } return nil } func init() { var opts CheckConfig _, err := parser.AddCommand( "check-config", "validate configuration", "Validate the configuration file", &opts, ) if err != nil { panic(err) } } |