all repos — searchix @ 6196d25ad331bdcbd0adc3da6facbcadc9bd3a1e

Search engine for NixOS, nix-darwin, home-manager and NUR users

feat: add check-config command

Alan Pearce
commit

6196d25ad331bdcbd0adc3da6facbcadc9bd3a1e

parent

e1c335c706bbf5dadb1f68dfc2026ab91b7a2508

1 file changed, 42 insertions(+), 0 deletions(-)

changed files
A cmd/searchix-web/check-config.go
@@ -0,0 +1,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) + } +}