Move hard out of flag args and into command

This commit is contained in:
2024-08-16 09:38:35 +02:00
parent 1f21965288
commit 2c49b65502
4 changed files with 9 additions and 5 deletions

View File

@@ -13,6 +13,7 @@ type LinkInstruction struct {
Source string Source string
Target string Target string
Force bool Force bool
Hard bool
} }
func (instruction *LinkInstruction) String() string { func (instruction *LinkInstruction) String() string {
@@ -35,6 +36,10 @@ func ParseInstruction(line string) (LinkInstruction, error) {
res, _ := regexp.MatchString(`^(?i)\s*T|TRUE\s*$`, parts[2]) res, _ := regexp.MatchString(`^(?i)\s*T|TRUE\s*$`, parts[2])
instruction.Force = res instruction.Force = res
} }
if len(parts) > 3 {
res, _ := regexp.MatchString(`^(?i)\s*T|TRUE\s*$`, parts[3])
instruction.Hard = res
}
instruction.Source, _ = ConvertHome(instruction.Source) instruction.Source, _ = ConvertHome(instruction.Source)
instruction.Target, _ = ConvertHome(instruction.Target) instruction.Target, _ = ConvertHome(instruction.Target)
@@ -123,7 +128,7 @@ func (instruction *LinkInstruction) RunAsync(status chan (error)) {
} }
var err error var err error
if *hard { if instruction.Hard {
err = os.Link(instruction.Source, instruction.Target) err = os.Link(instruction.Source, instruction.Target)
} else { } else {
err = os.Symlink(instruction.Source, instruction.Target) err = os.Symlink(instruction.Source, instruction.Target)

View File

@@ -32,13 +32,10 @@ var DirRegex, _ = regexp.Compile(`^(.+?)[/\\]sync$`)
var FileRegex, _ = regexp.Compile(`^sync$`) var FileRegex, _ = regexp.Compile(`^sync$`)
var programName = os.Args[0] var programName = os.Args[0]
var hard *bool
func main() { func main() {
recurse := flag.String("r", "", "recurse into directories") recurse := flag.String("r", "", "recurse into directories")
file := flag.String("f", "", "file to read instructions from") file := flag.String("f", "", "file to read instructions from")
debug := flag.Bool("d", false, "debug") debug := flag.Bool("d", false, "debug")
hard = flag.Bool("h", false, "create hard links instead")
flag.Parse() flag.Parse()
if *debug { if *debug {

3
sync
View File

@@ -1 +1,2 @@
main.exe,"C:\Program Files\Git\usr\bin\cln.exe",t main.exe,"C:\Program Files\Git\usr\bin\cln.exe",t
main.exe,"~/Seafile/Other/cln.exe",,t

1
testsync Normal file
View File

@@ -0,0 +1 @@
foo,bar,,t