summaryrefslogtreecommitdiff
path: root/cmd/gotosocial/common.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/gotosocial/common.go')
-rw-r--r--cmd/gotosocial/common.go17
1 files changed, 15 insertions, 2 deletions
diff --git a/cmd/gotosocial/common.go b/cmd/gotosocial/common.go
index 0c65be657..48d56a7a2 100644
--- a/cmd/gotosocial/common.go
+++ b/cmd/gotosocial/common.go
@@ -28,15 +28,22 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/log"
)
+type preRunArgs struct {
+ cmd *cobra.Command
+ skipValidation bool
+}
+
// preRun should be run in the pre-run stage of every cobra command.
// The goal here is to initialize the viper config store, and also read in
// the config file (if present).
//
+// Config then undergoes basic validation if 'skipValidation' is not true.
+//
// The order of these is important: the init-config function reads the location
// of the config file from the viper store so that it can be picked up by either
// env vars or cli flag.
-func preRun(cmd *cobra.Command) error {
- if err := config.InitViper(cmd.Flags()); err != nil {
+func preRun(a preRunArgs) error {
+ if err := config.InitViper(a.cmd.Flags()); err != nil {
return fmt.Errorf("error initializing viper: %s", err)
}
@@ -44,6 +51,12 @@ func preRun(cmd *cobra.Command) error {
return fmt.Errorf("error initializing config: %s", err)
}
+ if !a.skipValidation {
+ if err := config.Validate(); err != nil {
+ return fmt.Errorf("invalid config: %s", err)
+ }
+ }
+
return nil
}