diff --git a/instruction.go b/instruction.go index 5da64ea..56e8177 100644 --- a/instruction.go +++ b/instruction.go @@ -20,6 +20,7 @@ func (instruction *LinkInstruction) String() string { } func ParseInstruction(line string) (LinkInstruction, error) { + line = strings.TrimSpace(line) parts := strings.Split(line, deliminer) instruction := LinkInstruction{} @@ -27,11 +28,11 @@ func ParseInstruction(line string) (LinkInstruction, error) { return instruction, fmt.Errorf("invalid format - not enough parameters (must have at least source and target)") } - instruction.Source = parts[0] - instruction.Target = parts[1] + instruction.Source = strings.TrimSpace(parts[0]) + instruction.Target = strings.TrimSpace(parts[1]) instruction.Force = false if len(parts) > 2 { - res, _ := regexp.MatchString("^(?i)T|TRUE$", parts[2]) + res, _ := regexp.MatchString(`^(?i)\s*T|TRUE\s*$`, parts[2]) instruction.Force = res } diff --git a/main.go b/main.go index 92a6dd4..fbd9e4c 100644 --- a/main.go +++ b/main.go @@ -54,7 +54,7 @@ func main() { log.Printf("Recurse: %s", *recurse) log.Printf("File: %s", *file) - instructions := make(chan LinkInstruction, 1000) + instructions := make(chan *LinkInstruction, 1000) status := make(chan error) if *recurse != "" { go ReadFromFilesRecursively(*recurse, instructions, status) @@ -110,7 +110,7 @@ func main() { } } -func ReadFromFilesRecursively(input string, output chan LinkInstruction, status chan error) { +func ReadFromFilesRecursively(input string, output chan *LinkInstruction, status chan error) { defer close(output) defer close(status) @@ -165,7 +165,7 @@ func ReadFromFilesRecursively(input string, output chan LinkInstruction, status } wg.Wait() } -func ReadFromFile(input string, output chan LinkInstruction, status chan error, doclose bool) { +func ReadFromFile(input string, output chan *LinkInstruction, status chan error, doclose bool) { if doclose { defer close(output) defer close(status) @@ -189,10 +189,10 @@ func ReadFromFile(input string, output chan LinkInstruction, status chan error, continue } log.Printf("Read instruction: %s", instruction.String()) - output <- instruction + output <- &instruction } } -func ReadFromArgs(output chan LinkInstruction, status chan error) { +func ReadFromArgs(output chan *LinkInstruction, status chan error) { defer close(output) defer close(status) @@ -203,10 +203,10 @@ func ReadFromArgs(output chan LinkInstruction, status chan error) { log.Printf("Error parsing arg: %s'%s'%s, error: %s%+v%s", SourceColor, arg, DefaultColor, ErrorColor, err, DefaultColor) continue } - output <- instruction + output <- &instruction } } -func ReadFromStdin(output chan LinkInstruction, status chan error) { +func ReadFromStdin(output chan *LinkInstruction, status chan error) { defer close(output) defer close(status) @@ -227,7 +227,7 @@ func ReadFromStdin(output chan LinkInstruction, status chan error) { log.Printf("Error parsing line: %s'%s'%s, error: %s%+v%s", SourceColor, line, DefaultColor, ErrorColor, err, DefaultColor) continue } - output <- instruction + output <- &instruction } if err := scanner.Err(); err != nil { log.Fatalf("Error reading from stdin: %s%+v%s", ErrorColor, err, DefaultColor)