diff --git a/config.go b/config.go new file mode 100644 index 0000000..7ea0546 --- /dev/null +++ b/config.go @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2015 Alex Yatskov + * Author: Alex Yatskov + * + * 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) +} diff --git a/config.toml b/config.toml index 7cb83bd..0bc7ab8 100644 --- a/config.toml +++ b/config.toml @@ -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" diff --git a/link.go b/link.go new file mode 100644 index 0000000..704d9d3 --- /dev/null +++ b/link.go @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2015 Alex Yatskov + * Author: Alex Yatskov + * + * 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 +} diff --git a/main.go b/main.go index 484da6e..8a558c5 100644 --- a/main.go +++ b/main.go @@ -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) } diff --git a/profile.go b/profile.go new file mode 100644 index 0000000..799d676 --- /dev/null +++ b/profile.go @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2015 Alex Yatskov + * Author: Alex Yatskov + * + * 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 +}