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-04-02 09:16:59 +00:00
|
|
|
"fmt"
|
2015-03-31 05:51:43 +00:00
|
|
|
"log"
|
2015-04-02 09:16:59 +00:00
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2015-08-10 09:33:22 +00:00
|
|
|
flagClobber = 1 << iota
|
|
|
|
flagForce
|
|
|
|
flagVerbose
|
2015-09-06 05:45:57 +00:00
|
|
|
flagNoCmds
|
|
|
|
flagNoLinks
|
2015-08-10 09:33:22 +00:00
|
|
|
flagNoMacro
|
2015-09-06 05:45:57 +00:00
|
|
|
flagUnlink = flagNoCmds | (1 << iota)
|
2015-03-31 05:51:43 +00:00
|
|
|
)
|
|
|
|
|
2015-04-03 03:58:41 +00:00
|
|
|
func usage() {
|
2015-08-10 04:48:57 +00:00
|
|
|
fmt.Fprintf(os.Stderr, "Usage: %s [options] conf src\n", path.Base(os.Args[0]))
|
2015-05-18 02:11:25 +00:00
|
|
|
fmt.Fprintf(os.Stderr, "http://foosoft.net/projects/homemaker/\n\n")
|
|
|
|
fmt.Fprintf(os.Stderr, "Parameters:\n")
|
2015-04-02 09:16:59 +00:00
|
|
|
flag.PrintDefaults()
|
2015-04-02 02:16:45 +00:00
|
|
|
}
|
|
|
|
|
2015-03-31 11:59:09 +00:00
|
|
|
func main() {
|
2015-04-02 09:16:59 +00:00
|
|
|
taskName := flag.String("task", "default", "name of task to execute")
|
2015-11-08 01:18:19 +00:00
|
|
|
dstDir := flag.String("dest", os.Getenv("HOME"), "target directory for tasks")
|
2015-04-02 09:16:59 +00:00
|
|
|
force := flag.Bool("force", true, "create parent directories to target")
|
2015-04-02 02:16:45 +00:00
|
|
|
clobber := flag.Bool("clobber", false, "delete files and directories at target")
|
2015-04-02 09:16:59 +00:00
|
|
|
verbose := flag.Bool("verbose", false, "verbose output")
|
2015-09-06 05:45:57 +00:00
|
|
|
nocmds := flag.Bool("nocmds", false, "don't execute commands")
|
|
|
|
nolinks := flag.Bool("nolinks", false, "don't create links")
|
|
|
|
variant := flag.String("variant", "", "execution variant for tasks and macros")
|
|
|
|
unlink := flag.Bool("unlink", false, "remove existing links instead of creating them")
|
2015-04-02 02:16:45 +00:00
|
|
|
|
2015-04-03 03:58:41 +00:00
|
|
|
flag.Usage = usage
|
2015-04-02 02:16:45 +00:00
|
|
|
flag.Parse()
|
|
|
|
|
2015-04-02 09:16:59 +00:00
|
|
|
flags := 0
|
|
|
|
if *clobber {
|
2015-08-10 09:33:22 +00:00
|
|
|
flags |= flagClobber
|
2015-04-02 09:16:59 +00:00
|
|
|
}
|
|
|
|
if *force {
|
2015-08-10 09:33:22 +00:00
|
|
|
flags |= flagForce
|
2015-04-02 09:16:59 +00:00
|
|
|
}
|
|
|
|
if *verbose {
|
2015-08-10 09:33:22 +00:00
|
|
|
flags |= flagVerbose
|
2015-04-02 09:16:59 +00:00
|
|
|
}
|
2015-09-06 05:45:57 +00:00
|
|
|
if *nocmds {
|
|
|
|
flags |= flagNoCmds
|
2015-06-14 08:00:07 +00:00
|
|
|
}
|
2015-09-06 05:45:57 +00:00
|
|
|
if *nolinks {
|
|
|
|
flags |= flagNoLinks
|
|
|
|
}
|
|
|
|
if *unlink {
|
|
|
|
flags |= flagUnlink
|
2015-06-14 08:00:07 +00:00
|
|
|
}
|
2015-04-02 09:16:59 +00:00
|
|
|
|
2015-04-05 07:53:32 +00:00
|
|
|
if flag.NArg() == 2 {
|
2015-09-04 03:15:57 +00:00
|
|
|
confFile := makeAbsPath(flag.Arg(0))
|
2015-07-02 08:54:49 +00:00
|
|
|
|
2015-09-04 03:15:57 +00:00
|
|
|
conf, err := newConfig(confFile)
|
2015-04-05 07:53:32 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
2015-04-02 09:16:59 +00:00
|
|
|
}
|
2015-04-05 07:53:32 +00:00
|
|
|
|
2015-09-04 03:15:57 +00:00
|
|
|
conf.srcDir = makeAbsPath(flag.Arg(1))
|
|
|
|
conf.dstDir = makeAbsPath(*dstDir)
|
|
|
|
conf.variant = *variant
|
|
|
|
conf.flags = flags
|
|
|
|
|
|
|
|
os.Setenv("HM_CONFIG", confFile)
|
|
|
|
os.Setenv("HM_TASK", *taskName)
|
|
|
|
os.Setenv("HM_SRC", conf.srcDir)
|
|
|
|
os.Setenv("HM_DEST", conf.dstDir)
|
|
|
|
os.Setenv("HM_VARIANT", conf.variant)
|
|
|
|
|
|
|
|
if err := processTask(*taskName, conf); err != nil {
|
2015-04-02 09:16:59 +00:00
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2015-04-05 07:53:32 +00:00
|
|
|
} else {
|
2015-04-03 03:58:41 +00:00
|
|
|
usage()
|
|
|
|
os.Exit(2)
|
2015-04-02 02:16:45 +00:00
|
|
|
}
|
2015-03-31 04:37:32 +00:00
|
|
|
}
|