From 1a19a7ff8751bd7abd7b209c4d368d8eef42f975 Mon Sep 17 00:00:00 2001 From: Sig Lange Date: Sat, 26 Nov 2022 15:19:55 -0800 Subject: [PATCH] fix flag hangling for app global --- cleanup.go | 2 +- common.go | 21 +++++++++++---------- link.go | 3 +-- main.go | 2 ++ status.go | 2 +- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/cleanup.go b/cleanup.go index 5a6d8c0..049c0cf 100644 --- a/cleanup.go +++ b/cleanup.go @@ -15,7 +15,7 @@ func (me *Cleanup) Flags() []cli.Flag { } func (me *Cleanup) Run(c *cli.Context) error { - configfiles := getConfigFiles(c) + configfiles := me.ctx.getConfigFiles(c) for _, filename := range configfiles { err := me.RunFile(filename) diff --git a/common.go b/common.go index 12d2736..7c1f7b1 100644 --- a/common.go +++ b/common.go @@ -6,9 +6,18 @@ import ( "github.com/urfave/cli/v2" ) -func getConfigFiles(c *cli.Context) []string { +type Context struct { + app *cli.App + configs []string +} + +func (me *Context) addCommand(cmd *cli.Command) { + me.app.Commands = append(me.app.Commands, cmd) +} + +func (me *Context) getConfigFiles(c *cli.Context) []string { defaultFile := "dotbot.yaml" - ret := c.StringSlice("config") + ret := me.configs if len(ret) == 0 { st, err := os.Stat(defaultFile) @@ -19,11 +28,3 @@ func getConfigFiles(c *cli.Context) []string { } return ret } - -type Context struct { - app *cli.App -} - -func (me *Context) addCommand(cmd *cli.Command) { - me.app.Commands = append(me.app.Commands, cmd) -} diff --git a/link.go b/link.go index 01a93f8..52cab92 100644 --- a/link.go +++ b/link.go @@ -40,7 +40,7 @@ type LinkOptions struct { func (me *Link) Run(c *cli.Context) error { opts := &LinkOptions{} - configfiles := getConfigFiles(c) + configfiles := me.ctx.getConfigFiles(c) opts.Pretend = c.Bool("pretend") opts.AutoMode = c.Bool("auto") log.Tracef("%d files to execute", len(configfiles)) @@ -165,7 +165,6 @@ func (me *Link) RunAutoMode(opts *LinkOptions) error { return err } - // build config using current directory listing for _, filename := range filenames { if filename == ".git" { diff --git a/main.go b/main.go index 0d3d50a..3e20e88 100644 --- a/main.go +++ b/main.go @@ -37,6 +37,8 @@ func main() { gologging.SetLogLevel(loglevel) } + ctx.configs = c.StringSlice("config") + return nil }, } diff --git a/status.go b/status.go index 46c5907..6b0de8b 100644 --- a/status.go +++ b/status.go @@ -29,7 +29,7 @@ func (me *Status) Flags() []cli.Flag { } func (me *Status) Run(c *cli.Context) error { - configfiles := getConfigFiles(c) + configfiles := me.ctx.getConfigFiles(c) asJson := c.Bool("json") showAll := c.Bool("all")