diff --git a/clean.go b/clean.go index 7f0a864..51bb77a 100644 --- a/clean.go +++ b/clean.go @@ -50,8 +50,8 @@ func (me *Clean) RunConfig(cfg *AppConfig, path string) error { return nil } func (me *Clean) CleanUnreferenced(cfg *AppConfig, path string) error { - - run, err := CompileRun(path, cfg.Symlinks, cfg.WalkDir, cfg.Script, cfg.Include) + p := NewRunParamsConfig(cfg) + run, err := CompileRun(path, p) if err != nil { return err } diff --git a/link.go b/link.go index be3e01e..af5f514 100644 --- a/link.go +++ b/link.go @@ -99,7 +99,8 @@ func (me *Link) RunFile(opts *LinkOptions, path string) error { func (me *Link) RunConfig(path string, opts *LinkOptions, cfg *AppConfig) error { // compile run - run, err := CompileRun(path, cfg.Symlinks, cfg.WalkDir, cfg.Script, cfg.Include) + p := NewRunParamsConfig(cfg) + run, err := CompileRun(path, p) if err != nil { return err } @@ -253,8 +254,8 @@ func (me *Link) RunAutoMode(opts *LinkOptions) error { } cfg.Symlinks["~/"+filename] = filename } - - run, err := CompileRun("", cfg.Symlinks, cfg.WalkDir, cfg.Script, cfg.Include) + p := NewRunParamsConfig(cfg) + run, err := CompileRun("", p) if err != nil { return err } diff --git a/run.go b/run.go index a1ce034..b23e03f 100644 --- a/run.go +++ b/run.go @@ -34,22 +34,34 @@ type LinkInfo struct { NeedsCreate bool } -func CompileRun(path string, symlinks, walkdir map[string]string, script []*Script, include []string) (*Run, error) { +func NewRunParamsConfig(c *AppConfig) *RunParams { + ret := &RunParams{} + ret.Symlinks = c.Symlinks + ret.Walkdir = c.WalkDir + ret.Script = c.Script + ret.Mkdir = c.Mkdirs + ret.Include = c.Include + return ret +} + +type RunParams struct { + Symlinks map[string]string + Walkdir map[string]string + Script []*Script + Mkdir []string + Include []string +} + +func CompileRun(path string, p *RunParams) (*Run, error) { run := NewRun() - err := CompileRunWithRun(run, path, symlinks, walkdir, script, include) + err := CompileRunWithRun(path, run, p) if err != nil { return nil, err } return run, nil } -func CompileRunWithRun( - run *Run, - path string, - symlinks, - walkdir map[string]string, - script []*Script, - include []string) error { +func CompileRunWithRun(path string, run *Run, p *RunParams) error { // change dir and then change back before returning dir, _ := os.Getwd() @@ -60,26 +72,26 @@ func CompileRunWithRun( }() // scripts - for _, s := range script { + for _, s := range p.Script { if s.Disabled { continue } run.Script = append(run.Script, s) } - err := CompileRunSymlinks(run, symlinks) + err := CompileRunSymlinks(run, p.Symlinks) if err != nil { log.Warnf("CompileRunSymlinks %s", err) return err } - err = CompileRunWalkDir(run, walkdir) + err = CompileRunWalkDir(run, p.Walkdir) if err != nil { log.Warnf("CompileRunWalkDir %s", err) return err } - includes, err := GetIncludes(path, include) + includes, err := GetIncludes(path, p.Include) if err != nil { log.Warnf("GetIncludes %s", err) return err @@ -91,7 +103,8 @@ func CompileRunWithRun( log.Errorf("Include %s: %s", include, err) continue } - err = CompileRunWithRun(run, include, cfg2.Symlinks, cfg2.WalkDir, cfg2.Script, cfg2.Include) + p2 := NewRunParamsConfig(cfg2) + err = CompileRunWithRun(include, run, p2) if err != nil { log.Errorf("Include CompileRunWithRun %s: %s", include, err) continue diff --git a/status.go b/status.go index 12d2eaa..42c55dd 100644 --- a/status.go +++ b/status.go @@ -58,8 +58,8 @@ func (me *Status) RunFile(path string, asJson, showAll bool) error { if log.IsTrace() { cfg.PrintConfig() } - - run, err := CompileRun(path, cfg.Symlinks, cfg.WalkDir, cfg.Script, cfg.Include) + p := NewRunParamsConfig(cfg) + run, err := CompileRun(path, p) if err != nil { return err } diff --git a/unlink.go b/unlink.go index 354dbf4..541b51a 100644 --- a/unlink.go +++ b/unlink.go @@ -80,7 +80,8 @@ func (me *Unlink) RunFile(opts *UnlinkOptions, path string) error { } func (me *Unlink) RunConfig(opts *UnlinkOptions, cfg *AppConfig, path string) error { - run, err := CompileRun(path, cfg.Symlinks, cfg.WalkDir, cfg.Script, cfg.Include) + p := NewRunParamsConfig(cfg) + run, err := CompileRun(path, p) if err != nil { return err } @@ -147,7 +148,8 @@ func (me *Unlink) RunAutoMode(opts *UnlinkOptions) error { cfg.Symlinks["~/"+filename] = filename } - run, err := CompileRun("", cfg.Symlinks, cfg.WalkDir, cfg.Script, cfg.Include) + p := NewRunParamsConfig(cfg) + run, err := CompileRun("", p) if err != nil { return err }