Skip to content

Commit

Permalink
switch to RunParams
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmonsays committed Apr 11, 2024
1 parent 4e60d9c commit 1ef824d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 23 deletions.
4 changes: 2 additions & 2 deletions clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 4 additions & 3 deletions link.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
41 changes: 27 additions & 14 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 4 additions & 2 deletions unlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 1ef824d

Please sign in to comment.