Refactoring

This commit is contained in:
Alex Yatskov 2015-04-02 11:29:04 +09:00
parent 834bccdace
commit e026f82efd
4 changed files with 29 additions and 29 deletions

View File

@ -25,14 +25,14 @@ package main
import "fmt" import "fmt"
type config struct { type config struct {
Profs map[string]profile Tasks map[string]task
} }
func (this config) process(name, srcDir, dstDir string) error { func (this config) install(name, srcDir, dstDir string) error {
prof, ok := this.Profs[name] task, ok := this.Tasks[name]
if !ok { if !ok {
return fmt.Errorf("Profile not found: '%s'", name) return fmt.Errorf("Profile not found: '%s'", name)
} }
return prof.process(srcDir, dstDir, this) return task.install(srcDir, dstDir, this)
} }

View File

@ -1,48 +1,48 @@
[profs.dev] [tasks.dev]
[[profs.dev.links]] [[tasks.dev.links]]
src = ".gitconfig" src = ".gitconfig"
[profs.base] [tasks.base]
[[profs.base.links]] [[tasks.base.links]]
src = ".config/fish" src = ".config/fish"
[[profs.base.links]] [[tasks.base.links]]
src = ".config/keepassx" src = ".config/keepassx"
[[profs.base.links]] [[tasks.base.links]]
src = ".filezilla" src = ".filezilla"
[[profs.base.links]] [[tasks.base.links]]
src = "profile" src = "profile"
[profs.study] [tasks.study]
[[profs.study.links]] [[tasks.study.links]]
src = "Anki" src = "Anki"
[[profs.study.links]] [[tasks.study.links]]
src = ".yomichan.json" src = ".yomichan.json"
[profs.net] [tasks.net]
[[profs.net.links]] [[tasks.net.links]]
src = ".filezilla" src = ".filezilla"
[[profs.net.links]] [[tasks.net.links]]
src = ".s3cfg" src = ".s3cfg"
[profs.flatline] [tasks.flatline]
deps = ["base", "dev", "study", "net"] deps = ["base", "dev", "study", "net"]
[[profs.flatline.links]] [[tasks.flatline.links]]
src = ".ssh_flatline" src = ".ssh_flatline"
dst = ".ssh" dst = ".ssh"
[[profs.flatline.links]] [[tasks.flatline.links]]
src = ".config/syncthing_flatline" src = ".config/syncthing_flatline"
dst = ".config/syncthing" dst = ".config/syncthing"
[profs.wintermute] [tasks.wintermute]
deps = ["base", "dev", "study"] deps = ["base", "dev", "study"]
[[profs.wintermute.links]] [[tasks.wintermute.links]]
src = ".ssh_wintermute" src = ".ssh_wintermute"
dst = ".ssh" dst = ".ssh"

View File

@ -62,7 +62,7 @@ func preparePath(loc string, force, clobber bool) error {
return nil return nil
} }
func (this link) process(srcDir, dstDir string) error { func (this link) install(srcDir, dstDir string) error {
if len(this.Dst) == 0 { if len(this.Dst) == 0 {
this.Dst = this.Src this.Dst = this.Src
} }

View File

@ -24,25 +24,25 @@ package main
import "fmt" import "fmt"
type profile struct { type task struct {
Deps []string Deps []string
Links []link Links []link
} }
func (this profile) process(srcDir, dstDir string, conf config) error { func (this task) install(srcDir, dstDir string, conf config) error {
for _, name := range this.Deps { for _, name := range this.Deps {
prof, ok := conf.Profs[name] depTask, ok := conf.Tasks[name]
if !ok { if !ok {
return fmt.Errorf("Profile dependency not found: '%s'", name) return fmt.Errorf("Task dependency not found: '%s'", name)
} }
if err := prof.process(srcDir, dstDir, conf); err != nil { if err := depTask.install(srcDir, dstDir, conf); err != nil {
return err return err
} }
} }
for _, link := range this.Links { for _, link := range this.Links {
if err := link.process(srcDir, dstDir); err != nil { if err := link.install(srcDir, dstDir); err != nil {
return err return err
} }
} }