Refactoring
This commit is contained in:
parent
834bccdace
commit
e026f82efd
@ -25,14 +25,14 @@ package main
|
||||
import "fmt"
|
||||
|
||||
type config struct {
|
||||
Profs map[string]profile
|
||||
Tasks map[string]task
|
||||
}
|
||||
|
||||
func (this config) process(name, srcDir, dstDir string) error {
|
||||
prof, ok := this.Profs[name]
|
||||
func (this config) install(name, srcDir, dstDir string) error {
|
||||
task, ok := this.Tasks[name]
|
||||
if !ok {
|
||||
return fmt.Errorf("Profile not found: '%s'", name)
|
||||
}
|
||||
|
||||
return prof.process(srcDir, dstDir, this)
|
||||
return task.install(srcDir, dstDir, this)
|
||||
}
|
||||
|
36
config.toml
36
config.toml
@ -1,48 +1,48 @@
|
||||
[profs.dev]
|
||||
[[profs.dev.links]]
|
||||
[tasks.dev]
|
||||
[[tasks.dev.links]]
|
||||
src = ".gitconfig"
|
||||
|
||||
[profs.base]
|
||||
[[profs.base.links]]
|
||||
[tasks.base]
|
||||
[[tasks.base.links]]
|
||||
src = ".config/fish"
|
||||
|
||||
[[profs.base.links]]
|
||||
[[tasks.base.links]]
|
||||
src = ".config/keepassx"
|
||||
|
||||
[[profs.base.links]]
|
||||
[[tasks.base.links]]
|
||||
src = ".filezilla"
|
||||
|
||||
[[profs.base.links]]
|
||||
[[tasks.base.links]]
|
||||
src = "profile"
|
||||
|
||||
[profs.study]
|
||||
[[profs.study.links]]
|
||||
[tasks.study]
|
||||
[[tasks.study.links]]
|
||||
src = "Anki"
|
||||
|
||||
[[profs.study.links]]
|
||||
[[tasks.study.links]]
|
||||
src = ".yomichan.json"
|
||||
|
||||
[profs.net]
|
||||
[[profs.net.links]]
|
||||
[tasks.net]
|
||||
[[tasks.net.links]]
|
||||
src = ".filezilla"
|
||||
|
||||
[[profs.net.links]]
|
||||
[[tasks.net.links]]
|
||||
src = ".s3cfg"
|
||||
|
||||
[profs.flatline]
|
||||
[tasks.flatline]
|
||||
deps = ["base", "dev", "study", "net"]
|
||||
|
||||
[[profs.flatline.links]]
|
||||
[[tasks.flatline.links]]
|
||||
src = ".ssh_flatline"
|
||||
dst = ".ssh"
|
||||
|
||||
[[profs.flatline.links]]
|
||||
[[tasks.flatline.links]]
|
||||
src = ".config/syncthing_flatline"
|
||||
dst = ".config/syncthing"
|
||||
|
||||
[profs.wintermute]
|
||||
[tasks.wintermute]
|
||||
deps = ["base", "dev", "study"]
|
||||
|
||||
[[profs.wintermute.links]]
|
||||
[[tasks.wintermute.links]]
|
||||
src = ".ssh_wintermute"
|
||||
dst = ".ssh"
|
||||
|
2
link.go
2
link.go
@ -62,7 +62,7 @@ func preparePath(loc string, force, clobber bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this link) process(srcDir, dstDir string) error {
|
||||
func (this link) install(srcDir, dstDir string) error {
|
||||
if len(this.Dst) == 0 {
|
||||
this.Dst = this.Src
|
||||
}
|
||||
|
@ -24,25 +24,25 @@ package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type profile struct {
|
||||
type task struct {
|
||||
Deps []string
|
||||
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 {
|
||||
prof, ok := conf.Profs[name]
|
||||
depTask, ok := conf.Tasks[name]
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
for _, link := range this.Links {
|
||||
if err := link.process(srcDir, dstDir); err != nil {
|
||||
if err := link.install(srcDir, dstDir); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user