summaryrefslogtreecommitdiff
path: root/cmd/gotosocial/main.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2021-12-07 13:31:39 +0100
committerLibravatar GitHub <noreply@github.com>2021-12-07 13:31:39 +0100
commit0884f89431cd26bcc9674b3b7ab628b090f5881e (patch)
treecdd3b3f77f780a8b59d075dbcc3d4d013811e405 /cmd/gotosocial/main.go
parentUpdate dependencies (#333) (diff)
downloadgotosocial-0884f89431cd26bcc9674b3b7ab628b090f5881e.tar.xz
Implement Cobra CLI tooling, Viper config tooling (#336)
* start pulling out + replacing urfave and config * replace many many instances of config * move more stuff => viper * properly remove urfave * move some flags to root command * add testrig commands to root * alias config file keys * start adding cli parsing tests * reorder viper init * remove config path alias * fmt * change config file keys to non-nested * we're more or less in business now * tidy up the common func * go fmt * get tests passing again * add note about the cliparsing tests * reorganize * update docs with changes * structure cmd dir better * rename + move some files around * fix dangling comma
Diffstat (limited to 'cmd/gotosocial/main.go')
-rw-r--r--cmd/gotosocial/main.go49
1 files changed, 35 insertions, 14 deletions
diff --git a/cmd/gotosocial/main.go b/cmd/gotosocial/main.go
index 87c44487c..a0b8b1046 100644
--- a/cmd/gotosocial/main.go
+++ b/cmd/gotosocial/main.go
@@ -19,38 +19,59 @@
package main
import (
- "os"
-
"github.com/sirupsen/logrus"
+ "github.com/spf13/cobra"
+ "github.com/spf13/viper"
+ "github.com/superseriousbusiness/gotosocial/cmd/gotosocial/flag"
_ "github.com/superseriousbusiness/gotosocial/docs"
- "github.com/urfave/cli/v2"
+ "github.com/superseriousbusiness/gotosocial/internal/config"
)
-// Version is the software version of GtS being used
+// Version is the software version of GtS being used.
var Version string
-// Commit is the git commit of GtS being used
+// Commit is the git commit of GtS being used.
var Commit string
//go:generate swagger generate spec
func main() {
var v string
- if Commit == "" {
+ if len(Commit) < 7 {
v = Version
} else {
v = Version + " " + Commit[:7]
}
- flagsSlice := getFlags()
- app := &cli.App{
- Version: v,
- Usage: "a fediverse social media server",
- Flags: flagsSlice,
- Commands: getCommands(flagsSlice),
+ // override software version in viper store
+ viper.Set(config.Keys.SoftwareVersion, v)
+
+ // 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://github.com/superseriousbusiness/gotosocial",
+ Version: v,
+ SilenceErrors: true,
+ SilenceUsage: true,
+ }
+
+ // attach global flags to the root command so that they can be accessed from any subcommand
+ flag.Global(rootCmd, config.Defaults)
+
+ // bind the config-path flag to viper early so that we can call it in the pre-run of following commands
+ if err := viper.BindPFlag(config.Keys.ConfigPath, rootCmd.PersistentFlags().Lookup(config.Keys.ConfigPath)); err != nil {
+ logrus.Fatalf("error attaching config flag: %s", err)
}
- if err := app.Run(os.Args); err != nil {
- logrus.Fatal(err)
+ // add subcommands
+ rootCmd.AddCommand(serverCommands())
+ rootCmd.AddCommand(testrigCommands())
+ rootCmd.AddCommand(debugCommands())
+ rootCmd.AddCommand(adminCommands())
+
+ // run
+ if err := rootCmd.Execute(); err != nil {
+ logrus.Fatalf("error executing command: %s", err)
}
}