summaryrefslogtreecommitdiff
path: root/cmd/gotosocial
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/gotosocial')
-rw-r--r--cmd/gotosocial/action/debug/config/config.go5
-rw-r--r--cmd/gotosocial/common.go8
-rw-r--r--cmd/gotosocial/debug.go2
-rw-r--r--cmd/gotosocial/main.go31
-rw-r--r--cmd/gotosocial/server.go3
5 files changed, 17 insertions, 32 deletions
diff --git a/cmd/gotosocial/action/debug/config/config.go b/cmd/gotosocial/action/debug/config/config.go
index bc2c379ca..f79f5234d 100644
--- a/cmd/gotosocial/action/debug/config/config.go
+++ b/cmd/gotosocial/action/debug/config/config.go
@@ -32,11 +32,8 @@ var Config action.GTSAction = func(ctx context.Context) (err error) {
// Marshal configuration to a raw JSON map
config.Config(func(cfg *config.Configuration) {
- raw, err = cfg.MarshalMap()
+ raw = cfg.MarshalMap()
})
- if err != nil {
- return err
- }
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
diff --git a/cmd/gotosocial/common.go b/cmd/gotosocial/common.go
index bc27f0147..bfa5b656d 100644
--- a/cmd/gotosocial/common.go
+++ b/cmd/gotosocial/common.go
@@ -43,16 +43,16 @@ type preRunArgs struct {
// env vars or cli flag.
func preRun(a preRunArgs) error {
if err := config.BindFlags(a.cmd); err != nil {
- return fmt.Errorf("error binding flags: %s", err)
+ return fmt.Errorf("error binding flags: %w", err)
}
- if err := config.Reload(); err != nil {
- return fmt.Errorf("error reloading config: %s", err)
+ if err := config.LoadConfigFile(); err != nil {
+ return fmt.Errorf("error loading config file: %w", err)
}
if !a.skipValidation {
if err := config.Validate(); err != nil {
- return fmt.Errorf("invalid config: %s", err)
+ return fmt.Errorf("invalid config: %w", err)
}
}
diff --git a/cmd/gotosocial/debug.go b/cmd/gotosocial/debug.go
index 4b819e8a6..f519e63bd 100644
--- a/cmd/gotosocial/debug.go
+++ b/cmd/gotosocial/debug.go
@@ -19,7 +19,6 @@ package main
import (
configaction "code.superseriousbusiness.org/gotosocial/cmd/gotosocial/action/debug/config"
- "code.superseriousbusiness.org/gotosocial/internal/config"
"github.com/spf13/cobra"
)
@@ -39,7 +38,6 @@ func debugCommands() *cobra.Command {
return run(cmd.Context(), configaction.Config)
},
}
- config.AddServerFlags(debugConfigCmd)
debugCmd.AddCommand(debugConfigCmd)
return debugCmd
}
diff --git a/cmd/gotosocial/main.go b/cmd/gotosocial/main.go
index a79b6a75c..5124147a7 100644
--- a/cmd/gotosocial/main.go
+++ b/cmd/gotosocial/main.go
@@ -23,10 +23,9 @@ import (
godebug "runtime/debug"
"strings"
- "github.com/spf13/cobra"
-
_ "code.superseriousbusiness.org/gotosocial/docs"
"code.superseriousbusiness.org/gotosocial/internal/config"
+ "github.com/spf13/cobra"
)
// Version is the version of GoToSocial being used.
@@ -41,24 +40,18 @@ func main() {
// override version in config store
config.SetSoftwareVersion(version)
- // instantiate the root command
- rootCmd := &cobra.Command{
- Use: "gotosocial",
- Short: "GoToSocial - a fediverse social media server",
- Long: "GoToSocial - a fediverse social media server\n\nFor help, see: https://docs.gotosocial.org.\n\nCode: https://codeberg.org/superseriousbusiness/gotosocial",
- Version: version,
- PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
- // before running any other cmd funcs, we must load config-path
- return config.LoadEarlyFlags(cmd)
- },
- SilenceErrors: true,
- SilenceUsage: true,
- }
+ rootCmd := new(cobra.Command)
+ rootCmd.Use = "gotosocial"
+ rootCmd.Short = "GoToSocial - a fediverse social media server"
+ rootCmd.Long = "GoToSocial - a fediverse social media server\n\nFor help, see: https://docs.gotosocial.org.\n\nCode: https://codeberg.org/superseriousbusiness/gotosocial"
+ rootCmd.Version = version
+ rootCmd.SilenceErrors = true
+ rootCmd.SilenceUsage = true
- // attach global flags to the root command so that they can be accessed from any subcommand
- config.AddGlobalFlags(rootCmd)
+ // Register global flags with root.
+ config.RegisterGlobalFlags(rootCmd)
- // add subcommands
+ // Add subcommands with their flags.
rootCmd.AddCommand(serverCommands())
rootCmd.AddCommand(debugCommands())
rootCmd.AddCommand(adminCommands())
@@ -70,7 +63,7 @@ func main() {
log.Fatal("gotosocial must be built and run with the DEBUG enviroment variable set to enable and access testrig")
}
- // run
+ // Run the prepared root command.
if err := rootCmd.Execute(); err != nil {
log.Fatalf("error executing command: %s", err)
}
diff --git a/cmd/gotosocial/server.go b/cmd/gotosocial/server.go
index 8b316aca8..859292402 100644
--- a/cmd/gotosocial/server.go
+++ b/cmd/gotosocial/server.go
@@ -19,7 +19,6 @@ package main
import (
"code.superseriousbusiness.org/gotosocial/cmd/gotosocial/action/server"
- "code.superseriousbusiness.org/gotosocial/internal/config"
"github.com/spf13/cobra"
)
@@ -39,7 +38,6 @@ func serverCommands() *cobra.Command {
return run(cmd.Context(), server.Start)
},
}
- config.AddServerFlags(serverStartCmd)
serverCmd.AddCommand(serverStartCmd)
serverMaintenanceCmd := &cobra.Command{
@@ -52,7 +50,6 @@ func serverCommands() *cobra.Command {
return run(cmd.Context(), server.Maintenance)
},
}
- config.AddServerFlags(serverMaintenanceCmd)
serverCmd.AddCommand(serverMaintenanceCmd)
return serverCmd