Skip to content

Commit

Permalink
Merge pull request #8 from sigmonsays/fix-config-flags
Browse files Browse the repository at this point in the history
fix flag hangling for app global
  • Loading branch information
sigmonsays authored Nov 26, 2022
2 parents f468e57 + 1a19a7f commit d783a13
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 11 additions & 10 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
3 changes: 1 addition & 2 deletions link.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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" {
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func main() {
gologging.SetLogLevel(loglevel)
}

ctx.configs = c.StringSlice("config")

return nil
},
}
Expand Down
2 changes: 1 addition & 1 deletion status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit d783a13

Please sign in to comment.