Trim instruction before parse
This commit is contained in:
@@ -20,6 +20,7 @@ func (instruction *LinkInstruction) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ParseInstruction(line string) (LinkInstruction, error) {
|
func ParseInstruction(line string) (LinkInstruction, error) {
|
||||||
|
line = strings.TrimSpace(line)
|
||||||
parts := strings.Split(line, deliminer)
|
parts := strings.Split(line, deliminer)
|
||||||
instruction := LinkInstruction{}
|
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)")
|
return instruction, fmt.Errorf("invalid format - not enough parameters (must have at least source and target)")
|
||||||
}
|
}
|
||||||
|
|
||||||
instruction.Source = parts[0]
|
instruction.Source = strings.TrimSpace(parts[0])
|
||||||
instruction.Target = parts[1]
|
instruction.Target = strings.TrimSpace(parts[1])
|
||||||
instruction.Force = false
|
instruction.Force = false
|
||||||
if len(parts) > 2 {
|
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
|
instruction.Force = res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
main.go
16
main.go
@@ -54,7 +54,7 @@ func main() {
|
|||||||
log.Printf("Recurse: %s", *recurse)
|
log.Printf("Recurse: %s", *recurse)
|
||||||
log.Printf("File: %s", *file)
|
log.Printf("File: %s", *file)
|
||||||
|
|
||||||
instructions := make(chan LinkInstruction, 1000)
|
instructions := make(chan *LinkInstruction, 1000)
|
||||||
status := make(chan error)
|
status := make(chan error)
|
||||||
if *recurse != "" {
|
if *recurse != "" {
|
||||||
go ReadFromFilesRecursively(*recurse, instructions, status)
|
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(output)
|
||||||
defer close(status)
|
defer close(status)
|
||||||
|
|
||||||
@@ -165,7 +165,7 @@ func ReadFromFilesRecursively(input string, output chan LinkInstruction, status
|
|||||||
}
|
}
|
||||||
wg.Wait()
|
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 {
|
if doclose {
|
||||||
defer close(output)
|
defer close(output)
|
||||||
defer close(status)
|
defer close(status)
|
||||||
@@ -189,10 +189,10 @@ func ReadFromFile(input string, output chan LinkInstruction, status chan error,
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
log.Printf("Read instruction: %s", instruction.String())
|
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(output)
|
||||||
defer close(status)
|
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)
|
log.Printf("Error parsing arg: %s'%s'%s, error: %s%+v%s", SourceColor, arg, DefaultColor, ErrorColor, err, DefaultColor)
|
||||||
continue
|
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(output)
|
||||||
defer close(status)
|
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)
|
log.Printf("Error parsing line: %s'%s'%s, error: %s%+v%s", SourceColor, line, DefaultColor, ErrorColor, err, DefaultColor)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
output <- instruction
|
output <- &instruction
|
||||||
}
|
}
|
||||||
if err := scanner.Err(); err != nil {
|
if err := scanner.Err(); err != nil {
|
||||||
log.Fatalf("Error reading from stdin: %s%+v%s", ErrorColor, err, DefaultColor)
|
log.Fatalf("Error reading from stdin: %s%+v%s", ErrorColor, err, DefaultColor)
|
||||||
|
Reference in New Issue
Block a user