homemaker/main.go

86 lines
2.5 KiB
Go
Raw Normal View History

2015-03-31 04:37:32 +00:00
/*
* 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
2015-03-31 05:51:43 +00:00
import (
2015-04-02 02:16:45 +00:00
"flag"
2015-03-31 05:51:43 +00:00
"github.com/naoina/toml"
"io/ioutil"
"log"
2015-04-02 02:16:45 +00:00
"os/user"
2015-03-31 05:51:43 +00:00
)
2015-03-31 11:59:09 +00:00
func parse(filename string) (*config, error) {
bytes, err := ioutil.ReadFile(filename)
2015-03-31 05:51:43 +00:00
if err != nil {
2015-03-31 11:59:09 +00:00
return nil, err
2015-03-31 05:51:43 +00:00
}
2015-03-31 11:59:09 +00:00
conf := &config{}
if err := toml.Unmarshal(bytes, &conf); err != nil {
return nil, err
2015-03-31 05:51:43 +00:00
}
2015-03-31 11:59:09 +00:00
return conf, nil
}
2015-04-02 02:16:45 +00:00
func install(conf config, name, target, source string, force, clobber bool) error {
return nil
}
func uninstall(conf config, name, target string, force, clobber bool) error {
return nil
}
2015-03-31 11:59:09 +00:00
func main() {
2015-04-02 02:16:45 +00:00
currUsr, err := user.Current()
if err == nil {
2015-03-31 05:51:43 +00:00
log.Fatal(err)
}
2015-03-31 04:37:32 +00:00
2015-04-02 02:16:45 +00:00
action := flag.String("action", "install", "'install' or 'uninstall' symlinks")
clobber := flag.Bool("clobber", false, "delete files and directories at target")
force := flag.Bool("force", true, "force creation of parent directories for target")
profile := flag.String("profile", "default", "name of profile to execute")
target := flag.String("target", currUsr.HomeDir, "target directory for symlinks")
flag.Parse()
confPath := flag.Arg(0)
source := flag.Arg(1)
conf, err := parse(confPath)
if err != nil {
2015-03-31 12:06:45 +00:00
log.Fatal(err)
}
2015-04-02 02:16:45 +00:00
switch *action {
case "install":
install(*conf, *profile, *target, source, *force, *clobber)
case "uninstall":
uninstall(*conf, *profile, *target, *force, *clobber)
default:
log.Fatalf("Unrecognized action: '%s'", action)
}
2015-03-31 04:37:32 +00:00
}