parent
db4c127550
commit
813de95ee7
@ -56,7 +56,7 @@ func processCmd(params []string, dir string, conf *config, flags int) error {
|
|||||||
}
|
}
|
||||||
margs = appendExpEnv(margs, m.Suffix)
|
margs = appendExpEnv(margs, m.Suffix)
|
||||||
|
|
||||||
if flags&FLAG_VERBOSE == FLAG_VERBOSE {
|
if flags&flagVerbose == flagVerbose {
|
||||||
log.Printf("using macro %s", macroName)
|
log.Printf("using macro %s", macroName)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ func processCmd(params []string, dir string, conf *config, flags int) error {
|
|||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
|
|
||||||
if flags&FLAG_VERBOSE == FLAG_VERBOSE {
|
if flags&flagVerbose == flagVerbose {
|
||||||
log.Printf("executing command %s %s", cmdName, strings.Join(cmdArgs, " "))
|
log.Printf("executing command %s %s", cmdName, strings.Join(cmdArgs, " "))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ func processEnv(env []string, flags int) error {
|
|||||||
case len(args) == 0:
|
case len(args) == 0:
|
||||||
return fmt.Errorf("invalid environment statement")
|
return fmt.Errorf("invalid environment statement")
|
||||||
case len(args) == 1:
|
case len(args) == 1:
|
||||||
if flags&FLAG_VERBOSE == FLAG_VERBOSE {
|
if flags&flagVerbose == flagVerbose {
|
||||||
log.Printf("unsetting variable %s", args[0])
|
log.Printf("unsetting variable %s", args[0])
|
||||||
}
|
}
|
||||||
os.Unsetenv(args[0])
|
os.Unsetenv(args[0])
|
||||||
@ -48,7 +48,7 @@ func processEnv(env []string, flags int) error {
|
|||||||
value = strings.Join(args[1:], ",")
|
value = strings.Join(args[1:], ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
if flags&FLAG_VERBOSE == FLAG_VERBOSE {
|
if flags&flagVerbose == flagVerbose {
|
||||||
log.Printf("setting variable %s to %s", args[0], value)
|
log.Printf("setting variable %s to %s", args[0], value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
22
homemaker.go
22
homemaker.go
@ -37,12 +37,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
FLAG_CLOBBER = 1 << iota
|
flagClobber = 1 << iota
|
||||||
FLAG_FORCE
|
flagForce
|
||||||
FLAG_VERBOSE
|
flagVerbose
|
||||||
FLAG_NO_CMD
|
flagNoCmd
|
||||||
FLAG_NO_LINK
|
flagNoLink
|
||||||
FLAG_NO_MACRO
|
flagNoMacro
|
||||||
)
|
)
|
||||||
|
|
||||||
func parseCfg(filename string) (*config, error) {
|
func parseCfg(filename string) (*config, error) {
|
||||||
@ -98,19 +98,19 @@ func main() {
|
|||||||
|
|
||||||
flags := 0
|
flags := 0
|
||||||
if *clobber {
|
if *clobber {
|
||||||
flags |= FLAG_CLOBBER
|
flags |= flagClobber
|
||||||
}
|
}
|
||||||
if *force {
|
if *force {
|
||||||
flags |= FLAG_FORCE
|
flags |= flagForce
|
||||||
}
|
}
|
||||||
if *verbose {
|
if *verbose {
|
||||||
flags |= FLAG_VERBOSE
|
flags |= flagVerbose
|
||||||
}
|
}
|
||||||
if *nocmd {
|
if *nocmd {
|
||||||
flags |= FLAG_NO_CMD
|
flags |= flagNoCmd
|
||||||
}
|
}
|
||||||
if *nolink {
|
if *nolink {
|
||||||
flags |= FLAG_NO_LINK
|
flags |= flagNoLink
|
||||||
}
|
}
|
||||||
|
|
||||||
if flag.NArg() == 2 {
|
if flag.NArg() == 2 {
|
||||||
|
12
link.go
12
link.go
@ -33,15 +33,15 @@ import (
|
|||||||
func cleanPath(loc string, flags int) error {
|
func cleanPath(loc string, flags int) error {
|
||||||
if info, _ := os.Lstat(loc); info != nil {
|
if info, _ := os.Lstat(loc); info != nil {
|
||||||
if info.Mode()&os.ModeSymlink == os.ModeSymlink {
|
if info.Mode()&os.ModeSymlink == os.ModeSymlink {
|
||||||
if flags&FLAG_VERBOSE == FLAG_VERBOSE {
|
if flags&flagVerbose == flagVerbose {
|
||||||
log.Printf("removing symlink %s", loc)
|
log.Printf("removing symlink %s", loc)
|
||||||
}
|
}
|
||||||
if err := os.Remove(loc); err != nil {
|
if err := os.Remove(loc); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if flags&FLAG_CLOBBER == FLAG_CLOBBER {
|
if flags&flagClobber == flagClobber {
|
||||||
if flags&FLAG_VERBOSE == FLAG_VERBOSE {
|
if flags&flagVerbose == flagVerbose {
|
||||||
log.Printf("clobbering path %s", loc)
|
log.Printf("clobbering path %s", loc)
|
||||||
}
|
}
|
||||||
if err := os.RemoveAll(loc); err != nil {
|
if err := os.RemoveAll(loc); err != nil {
|
||||||
@ -55,10 +55,10 @@ func cleanPath(loc string, flags int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createPath(loc string, flags int, mode os.FileMode) error {
|
func createPath(loc string, flags int, mode os.FileMode) error {
|
||||||
if flags&FLAG_FORCE == FLAG_FORCE {
|
if flags&flagForce == flagForce {
|
||||||
parentDir, _ := path.Split(loc)
|
parentDir, _ := path.Split(loc)
|
||||||
if _, err := os.Stat(parentDir); os.IsNotExist(err) {
|
if _, err := os.Stat(parentDir); os.IsNotExist(err) {
|
||||||
if flags&FLAG_VERBOSE == FLAG_VERBOSE {
|
if flags&flagVerbose == flagVerbose {
|
||||||
log.Printf("force creating path %s", parentDir)
|
log.Printf("force creating path %s", parentDir)
|
||||||
}
|
}
|
||||||
if err := os.MkdirAll(parentDir, mode); err != nil {
|
if err := os.MkdirAll(parentDir, mode); err != nil {
|
||||||
@ -126,7 +126,7 @@ func processLink(params []string, srcDir, dstDir string, flags int) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if flags&FLAG_VERBOSE == FLAG_VERBOSE {
|
if flags&flagVerbose == flagVerbose {
|
||||||
log.Printf("linking %s to %s", srcPathAbs, dstPathAbs)
|
log.Printf("linking %s to %s", srcPathAbs, dstPathAbs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
task.go
4
task.go
@ -44,7 +44,7 @@ func (t *task) process(srcDir, dstDir string, conf *config, flags int) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if flags&FLAG_NO_CMD == 0 {
|
if flags&flagNoCmd == 0 {
|
||||||
for _, currCmd := range t.Cmds {
|
for _, currCmd := range t.Cmds {
|
||||||
if err := processCmd(currCmd, dstDir, conf, flags); err != nil {
|
if err := processCmd(currCmd, dstDir, conf, flags); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -52,7 +52,7 @@ func (t *task) process(srcDir, dstDir string, conf *config, flags int) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if flags&FLAG_NO_LINK == 0 {
|
if flags&flagNoLink == 0 {
|
||||||
for _, currLink := range t.Links {
|
for _, currLink := range t.Links {
|
||||||
if err := processLink(currLink, srcDir, dstDir, flags); err != nil {
|
if err := processLink(currLink, srcDir, dstDir, flags); err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user