This commit is contained in:
Alex Yatskov 2015-04-01 17:33:50 +09:00
parent cfa9601efe
commit 4adc700f1c
5 changed files with 116 additions and 37 deletions

38
config.go Normal file
View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2015 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package main
import "errors"
type config struct {
Profs map[string]profile
}
func (this config) process(name, src, dst string) error {
prof, ok := this.Profs[name]
if !ok {
return errors.New("Profile not found")
}
return prof.process(src, dst, this)
}

View File

@ -1,5 +1,3 @@
force = false
[profs.dev]
[[profs.dev.links]]
src = "vim/.vimrc"
@ -41,8 +39,6 @@ force = false
[profs.flatline]
deps = ["base", "dev", "study", "net"]
stomp = true
force = true
[[profs.flatline.links]]
src = ".ssh_flatline"
@ -54,8 +50,6 @@ force = false
[profs.wintermute]
deps = ["base", "dev", "study"]
stomp = true
force = true
[[profs.wintermute.links]]
src = ".ssh_wintermute"

32
link.go Normal file
View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2015 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package main
type link struct {
Dst string
Src string
}
func (this link) process(src, dst string) error {
return nil
}

32
main.go
View File

@ -28,26 +28,6 @@ import (
"log"
)
type link struct {
Dst string
Force bool
Src string
Stomp bool
}
type profile struct {
Deps []string
Force bool
Links []link
Stomp bool
}
type config struct {
Force bool
Profs map[string]profile
Stomp bool
}
func parse(filename string) (*config, error) {
bytes, err := ioutil.ReadFile(filename)
if err != nil {
@ -62,23 +42,13 @@ func parse(filename string) (*config, error) {
return conf, nil
}
func (conf *config) prepare() {
}
func process(src, dst string) error {
return nil
}
func main() {
conf, err := parse("config.toml")
if err != nil {
log.Fatal(err)
}
conf.prepare()
if err := process("/mnt/storage/sync/Dropbox", "/mnt/storage/projects/blah"); err != nil {
if err := conf.process("flatline", "/mnt/storage/sync/Dropbox", "/mnt/storage/projects/blah"); err != nil {
log.Fatal(err)
}

45
profile.go Normal file
View File

@ -0,0 +1,45 @@
/*
* Copyright (c) 2015 Alex Yatskov <alex@foosoft.net>
* Author: Alex Yatskov <alex@foosoft.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package main
import "errors"
type profile struct {
Deps []string
Links []link
}
func (this profile) process(src, dst string, conf config) error {
for _, name := range this.Deps {
prof, ok := conf.Profs[name]
if !ok {
return errors.New("Profile dependency not found")
}
if err := prof.process(src, dst, conf); err != nil {
return err
}
}
return nil
}