Adding unlink parameter
This commit is contained in:
parent
7f23ccc9f5
commit
67a97669ca
23
homemaker.go
23
homemaker.go
@ -35,9 +35,10 @@ const (
|
|||||||
flagClobber = 1 << iota
|
flagClobber = 1 << iota
|
||||||
flagForce
|
flagForce
|
||||||
flagVerbose
|
flagVerbose
|
||||||
flagNoCmd
|
flagNoCmds
|
||||||
flagNoLink
|
flagNoLinks
|
||||||
flagNoMacro
|
flagNoMacro
|
||||||
|
flagUnlink = flagNoCmds | (1 << iota)
|
||||||
)
|
)
|
||||||
|
|
||||||
func usage() {
|
func usage() {
|
||||||
@ -58,9 +59,10 @@ func main() {
|
|||||||
force := flag.Bool("force", true, "create parent directories to target")
|
force := flag.Bool("force", true, "create parent directories to target")
|
||||||
clobber := flag.Bool("clobber", false, "delete files and directories at target")
|
clobber := flag.Bool("clobber", false, "delete files and directories at target")
|
||||||
verbose := flag.Bool("verbose", false, "verbose output")
|
verbose := flag.Bool("verbose", false, "verbose output")
|
||||||
nocmd := flag.Bool("nocmd", false, "don't execute commands")
|
nocmds := flag.Bool("nocmds", false, "don't execute commands")
|
||||||
nolink := flag.Bool("nolink", false, "don't create links")
|
nolinks := flag.Bool("nolinks", false, "don't create links")
|
||||||
variant := flag.String("variant", "", "execution variant")
|
variant := flag.String("variant", "", "execution variant for tasks and macros")
|
||||||
|
unlink := flag.Bool("unlink", false, "remove existing links instead of creating them")
|
||||||
|
|
||||||
flag.Usage = usage
|
flag.Usage = usage
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
@ -75,11 +77,14 @@ func main() {
|
|||||||
if *verbose {
|
if *verbose {
|
||||||
flags |= flagVerbose
|
flags |= flagVerbose
|
||||||
}
|
}
|
||||||
if *nocmd {
|
if *nocmds {
|
||||||
flags |= flagNoCmd
|
flags |= flagNoCmds
|
||||||
}
|
}
|
||||||
if *nolink {
|
if *nolinks {
|
||||||
flags |= flagNoLink
|
flags |= flagNoLinks
|
||||||
|
}
|
||||||
|
if *unlink {
|
||||||
|
flags |= flagUnlink
|
||||||
}
|
}
|
||||||
|
|
||||||
if flag.NArg() == 2 {
|
if flag.NArg() == 2 {
|
||||||
|
9
link.go
9
link.go
@ -115,6 +115,7 @@ func processLink(params []string, conf *config) error {
|
|||||||
dstPathAbs = path.Join(conf.dstDir, dstPath)
|
dstPathAbs = path.Join(conf.dstDir, dstPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if conf.flags&flagUnlink == 0 {
|
||||||
if _, err := os.Stat(srcPathAbs); os.IsNotExist(err) {
|
if _, err := os.Stat(srcPathAbs); os.IsNotExist(err) {
|
||||||
return fmt.Errorf("source path %s does not exist in filesystem", srcPathAbs)
|
return fmt.Errorf("source path %s does not exist in filesystem", srcPathAbs)
|
||||||
}
|
}
|
||||||
@ -134,4 +135,12 @@ func processLink(params []string, conf *config) error {
|
|||||||
return try(func() error {
|
return try(func() error {
|
||||||
return os.Symlink(srcPathAbs, dstPathAbs)
|
return os.Symlink(srcPathAbs, dstPathAbs)
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
stat, err := os.Lstat(dstPathAbs)
|
||||||
|
if os.IsNotExist(err) || stat.Mode()&os.ModeSymlink == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return try(func() error { return cleanPath(dstPathAbs, conf.flags) })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
4
task.go
4
task.go
@ -47,7 +47,7 @@ func (t *task) process(conf *config) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if conf.flags&flagNoCmd == 0 {
|
if conf.flags&flagNoCmds == 0 {
|
||||||
for _, currCmd := range t.Cmds {
|
for _, currCmd := range t.Cmds {
|
||||||
if err := processCmd(currCmd, conf); err != nil {
|
if err := processCmd(currCmd, conf); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -55,7 +55,7 @@ func (t *task) process(conf *config) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if conf.flags&flagNoLink == 0 {
|
if conf.flags&flagNoLinks == 0 {
|
||||||
for _, currLink := range t.Links {
|
for _, currLink := range t.Links {
|
||||||
if err := processLink(currLink, conf); err != nil {
|
if err := processLink(currLink, conf); err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user