From 2c49b6550203afb247eefe3b9fbb9ac834839def Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Fri, 16 Aug 2024 09:38:35 +0200 Subject: [PATCH] Move hard out of flag args and into command --- instruction.go | 7 ++++++- main.go | 3 --- sync | 3 ++- testsync | 1 + 4 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 testsync diff --git a/instruction.go b/instruction.go index 1e05a47..cf69d61 100644 --- a/instruction.go +++ b/instruction.go @@ -13,6 +13,7 @@ type LinkInstruction struct { Source string Target string Force bool + Hard bool } 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]) 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.Target, _ = ConvertHome(instruction.Target) @@ -123,7 +128,7 @@ func (instruction *LinkInstruction) RunAsync(status chan (error)) { } var err error - if *hard { + if instruction.Hard { err = os.Link(instruction.Source, instruction.Target) } else { err = os.Symlink(instruction.Source, instruction.Target) diff --git a/main.go b/main.go index 9ec9988..fbd9e4c 100644 --- a/main.go +++ b/main.go @@ -32,13 +32,10 @@ var DirRegex, _ = regexp.Compile(`^(.+?)[/\\]sync$`) var FileRegex, _ = regexp.Compile(`^sync$`) var programName = os.Args[0] -var hard *bool - func main() { recurse := flag.String("r", "", "recurse into directories") file := flag.String("f", "", "file to read instructions from") debug := flag.Bool("d", false, "debug") - hard = flag.Bool("h", false, "create hard links instead") flag.Parse() if *debug { diff --git a/sync b/sync index e2193c8..7628058 100644 --- a/sync +++ b/sync @@ -1 +1,2 @@ -main.exe,"C:\Program Files\Git\usr\bin\cln.exe",t \ No newline at end of file +main.exe,"C:\Program Files\Git\usr\bin\cln.exe",t +main.exe,"~/Seafile/Other/cln.exe",,t \ No newline at end of file diff --git a/testsync b/testsync new file mode 100644 index 0000000..2a6f6f3 --- /dev/null +++ b/testsync @@ -0,0 +1 @@ +foo,bar,,t \ No newline at end of file