Style changes
This commit is contained in:
parent
8048effb1c
commit
a644ed8f7f
@ -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&flagVerbose == flagVerbose {
|
if flags&FLAG_VERBOSE == FLAG_VERBOSE {
|
||||||
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&flagVerbose == flagVerbose {
|
if flags&FLAG_VERBOSE == FLAG_VERBOSE {
|
||||||
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&flagVerbose == flagVerbose {
|
if flags&FLAG_VERBOSE == FLAG_VERBOSE {
|
||||||
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&flagVerbose == flagVerbose {
|
if flags&FLAG_VERBOSE == FLAG_VERBOSE {
|
||||||
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 (
|
||||||
flagClobber = 1 << iota
|
FLAG_CLOBBER = 1 << iota
|
||||||
flagForce
|
FLAG_FORCE
|
||||||
flagVerbose
|
FLAG_VERBOSE
|
||||||
flagNoCmd
|
FLAG_NO_CMD
|
||||||
flagNoLink
|
FLAG_NO_LINK
|
||||||
flagNoMacro
|
FLAG_NO_MACRO
|
||||||
)
|
)
|
||||||
|
|
||||||
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 |= flagClobber
|
flags |= FLAG_CLOBBER
|
||||||
}
|
}
|
||||||
if *force {
|
if *force {
|
||||||
flags |= flagForce
|
flags |= FLAG_FORCE
|
||||||
}
|
}
|
||||||
if *verbose {
|
if *verbose {
|
||||||
flags |= flagVerbose
|
flags |= FLAG_VERBOSE
|
||||||
}
|
}
|
||||||
if *nocmd {
|
if *nocmd {
|
||||||
flags |= flagNoCmd
|
flags |= FLAG_NO_CMD
|
||||||
}
|
}
|
||||||
if *nolink {
|
if *nolink {
|
||||||
flags |= flagNoLink
|
flags |= FLAG_NO_LINK
|
||||||
}
|
}
|
||||||
|
|
||||||
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&flagVerbose == flagVerbose {
|
if flags&FLAG_VERBOSE == FLAG_VERBOSE {
|
||||||
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&flagClobber == flagClobber {
|
if flags&FLAG_CLOBBER == FLAG_CLOBBER {
|
||||||
if flags&flagVerbose == flagVerbose {
|
if flags&FLAG_VERBOSE == FLAG_VERBOSE {
|
||||||
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&flagForce == flagForce {
|
if flags&FLAG_FORCE == FLAG_FORCE {
|
||||||
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&flagVerbose == flagVerbose {
|
if flags&FLAG_VERBOSE == FLAG_VERBOSE {
|
||||||
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&flagVerbose == flagVerbose {
|
if flags&FLAG_VERBOSE == FLAG_VERBOSE {
|
||||||
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&flagNoCmd == 0 {
|
if flags&FLAG_NO_CMD == 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&flagNoLink == 0 {
|
if flags&FLAG_NO_LINK == 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