diff options
| author | 2025-05-06 15:51:45 +0000 | |
|---|---|---|
| committer | 2025-05-06 15:51:45 +0000 | |
| commit | 6acf56cde9fde972cf7c78f15d00ade262752c19 (patch) | |
| tree | 9e223bb35d9484756b019b576403b9e9d9f5a33d /cmd/gotosocial/main.go | |
| parent | [docs] Various little docs updates (#4144) (diff) | |
| download | gotosocial-6acf56cde9fde972cf7c78f15d00ade262752c19.tar.xz | |
[feature] support nested configuration files, and setting ALL configuration variables by CLI and env (#4109)
This updates our configuration code generator to now also include map marshal and unmarshalers. So we now have much more control over how things get read from pflags, and stored / read from viper configuration. This allows us to set ALL configuration variables by CLI and environment now, AND support nested configuration files. e.g.
```yaml
advanced:
scraper-deterrence = true
http-client:
allow-ips = ["127.0.0.1"]
```
is the same as
```yaml
advanced-scraper-deterrence = true
http-client-allow-ips = ["127.0.0.1"]
```
This also starts cleaning up of our jumbled Configuration{} type by moving the advanced configuration options into their own nested structs, also as a way to show what it's capable of. It's worth noting however that nesting only works if the Go types are nested too (as this is how we hint to our code generator to generate the necessary flattening code :p).
closes #3195
Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4109
Co-authored-by: kim <grufwub@gmail.com>
Co-committed-by: kim <grufwub@gmail.com>
Diffstat (limited to 'cmd/gotosocial/main.go')
| -rw-r--r-- | cmd/gotosocial/main.go | 31 |
1 files changed, 12 insertions, 19 deletions
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) } |
