diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/gotosocial/admincommands.go | 20 | ||||
-rw-r--r-- | cmd/gotosocial/commands.go | 8 | ||||
-rw-r--r-- | cmd/gotosocial/main.go | 5 | ||||
-rw-r--r-- | cmd/gotosocial/runaction.go | 35 | ||||
-rw-r--r-- | cmd/gotosocial/servercommands.go | 4 | ||||
-rw-r--r-- | cmd/gotosocial/testrigcommands.go | 4 |
6 files changed, 54 insertions, 22 deletions
diff --git a/cmd/gotosocial/admincommands.go b/cmd/gotosocial/admincommands.go index 5d505fe77..a70693b2c 100644 --- a/cmd/gotosocial/admincommands.go +++ b/cmd/gotosocial/admincommands.go @@ -25,7 +25,7 @@ import ( "github.com/urfave/cli/v2" ) -func adminCommands() []*cli.Command { +func adminCommands(allFlags []cli.Flag) []*cli.Command { return []*cli.Command{ { Name: "admin", @@ -56,7 +56,7 @@ func adminCommands() []*cli.Command { }, }, Action: func(c *cli.Context) error { - return runAction(c, account.Create) + return runAction(c, allFlags, account.Create) }, }, { @@ -70,7 +70,7 @@ func adminCommands() []*cli.Command { }, }, Action: func(c *cli.Context) error { - return runAction(c, account.Confirm) + return runAction(c, allFlags, account.Confirm) }, }, { @@ -84,7 +84,7 @@ func adminCommands() []*cli.Command { }, }, Action: func(c *cli.Context) error { - return runAction(c, account.Promote) + return runAction(c, allFlags, account.Promote) }, }, { @@ -98,7 +98,7 @@ func adminCommands() []*cli.Command { }, }, Action: func(c *cli.Context) error { - return runAction(c, account.Demote) + return runAction(c, allFlags, account.Demote) }, }, { @@ -112,7 +112,7 @@ func adminCommands() []*cli.Command { }, }, Action: func(c *cli.Context) error { - return runAction(c, account.Disable) + return runAction(c, allFlags, account.Disable) }, }, { @@ -126,7 +126,7 @@ func adminCommands() []*cli.Command { }, }, Action: func(c *cli.Context) error { - return runAction(c, account.Suspend) + return runAction(c, allFlags, account.Suspend) }, }, { @@ -145,7 +145,7 @@ func adminCommands() []*cli.Command { }, }, Action: func(c *cli.Context) error { - return runAction(c, account.Password) + return runAction(c, allFlags, account.Password) }, }, }, @@ -161,7 +161,7 @@ func adminCommands() []*cli.Command { }, }, Action: func(c *cli.Context) error { - return runAction(c, trans.Export) + return runAction(c, allFlags, trans.Export) }, }, { @@ -175,7 +175,7 @@ func adminCommands() []*cli.Command { }, }, Action: func(c *cli.Context) error { - return runAction(c, trans.Import) + return runAction(c, allFlags, trans.Import) }, }, }, diff --git a/cmd/gotosocial/commands.go b/cmd/gotosocial/commands.go index 0c16d1fb5..9b61a66ec 100644 --- a/cmd/gotosocial/commands.go +++ b/cmd/gotosocial/commands.go @@ -22,12 +22,12 @@ import ( "github.com/urfave/cli/v2" ) -func getCommands() []*cli.Command { +func getCommands(allFlags []cli.Flag) []*cli.Command { commands := []*cli.Command{} commandSets := [][]*cli.Command{ - serverCommands(), - adminCommands(), - testrigCommands(), + serverCommands(allFlags), + adminCommands(allFlags), + testrigCommands(allFlags), } for _, cs := range commandSets { commands = append(commands, cs...) diff --git a/cmd/gotosocial/main.go b/cmd/gotosocial/main.go index 3d41e0fda..87c44487c 100644 --- a/cmd/gotosocial/main.go +++ b/cmd/gotosocial/main.go @@ -42,11 +42,12 @@ func main() { v = Version + " " + Commit[:7] } + flagsSlice := getFlags() app := &cli.App{ Version: v, Usage: "a fediverse social media server", - Flags: getFlags(), - Commands: getCommands(), + Flags: flagsSlice, + Commands: getCommands(flagsSlice), } if err := app.Run(os.Args); err != nil { diff --git a/cmd/gotosocial/runaction.go b/cmd/gotosocial/runaction.go index c8af9ddbe..96c4edaf6 100644 --- a/cmd/gotosocial/runaction.go +++ b/cmd/gotosocial/runaction.go @@ -27,17 +27,48 @@ import ( "github.com/urfave/cli/v2" ) +type MonkeyPatchedCLIContext struct { + CLIContext *cli.Context + AllFlags []cli.Flag +} + +func (f MonkeyPatchedCLIContext) Bool(k string) bool { return f.CLIContext.Bool(k) } +func (f MonkeyPatchedCLIContext) String(k string) string { return f.CLIContext.String(k) } +func (f MonkeyPatchedCLIContext) StringSlice(k string) []string { return f.CLIContext.StringSlice(k) } +func (f MonkeyPatchedCLIContext) Int(k string) int { return f.CLIContext.Int(k) } +func (f MonkeyPatchedCLIContext) IsSet(k string) bool { + for _, flag := range f.AllFlags { + flagNames := flag.Names() + for _, name := range flagNames { + if name == k { + return flag.IsSet() + } + } + + } + return false +} + // runAction builds up the config and logger necessary for any // gotosocial action, and then executes the action. -func runAction(c *cli.Context, a cliactions.GTSAction) error { +func runAction(c *cli.Context, allFlags []cli.Flag, a cliactions.GTSAction) error { // create a new *config.Config based on the config path provided... conf, err := config.FromFile(c.String(config.GetFlagNames().ConfigPath)) if err != nil { return fmt.Errorf("error creating config: %s", err) } + // ... and the flags set on the *cli.Context by urfave - if err := conf.ParseCLIFlags(c, c.App.Version); err != nil { + // + // The IsSet function on the cli.Context object `c` here appears to have some issues right now, it always returns false in my tests. + // However we can re-create the behaviour we want by simply referencing the flag objects we created previously + // https://picopublish.sequentialread.com/files/chatlog_2021_11_18.txt + monkeyPatchedCLIContext := MonkeyPatchedCLIContext{ + CLIContext: c, + AllFlags: allFlags, + } + if err := conf.ParseCLIFlags(monkeyPatchedCLIContext, c.App.Version); err != nil { return fmt.Errorf("error parsing config: %s", err) } diff --git a/cmd/gotosocial/servercommands.go b/cmd/gotosocial/servercommands.go index 7a1692b79..fb6574216 100644 --- a/cmd/gotosocial/servercommands.go +++ b/cmd/gotosocial/servercommands.go @@ -23,7 +23,7 @@ import ( "github.com/urfave/cli/v2" ) -func serverCommands() []*cli.Command { +func serverCommands(allFlags []cli.Flag) []*cli.Command { return []*cli.Command{ { Name: "server", @@ -33,7 +33,7 @@ func serverCommands() []*cli.Command { Name: "start", Usage: "start the gotosocial server", Action: func(c *cli.Context) error { - return runAction(c, server.Start) + return runAction(c, allFlags, server.Start) }, }, }, diff --git a/cmd/gotosocial/testrigcommands.go b/cmd/gotosocial/testrigcommands.go index 9b9aa3806..aabe04267 100644 --- a/cmd/gotosocial/testrigcommands.go +++ b/cmd/gotosocial/testrigcommands.go @@ -23,7 +23,7 @@ import ( "github.com/urfave/cli/v2" ) -func testrigCommands() []*cli.Command { +func testrigCommands(allFlags []cli.Flag) []*cli.Command { return []*cli.Command{ { Name: "testrig", @@ -33,7 +33,7 @@ func testrigCommands() []*cli.Command { Name: "start", Usage: "start the gotosocial testrig", Action: func(c *cli.Context) error { - return runAction(c, testrig.Start) + return runAction(c, allFlags, testrig.Start) }, }, }, |