diff --git a/main.go b/main.go index 67ae687..10ccf59 100644 --- a/main.go +++ b/main.go @@ -67,7 +67,10 @@ func main() { go ReadFromStdin(instructions, status) default: - if _, err := os.Stat("sync.yaml"); err == nil { + if _, err := os.Stat("sync"); err == nil { + LogInfo("Using default sync file") + go ReadFromFile("sync", instructions, status, true) + } else if _, err := os.Stat("sync.yaml"); err == nil { LogInfo("Using default sync.yaml file") go ReadFromFile("sync.yaml", instructions, status, true) } else if _, err := os.Stat("sync.yml"); err == nil { @@ -224,6 +227,28 @@ func ReadFromFile(input string, output chan *LinkInstruction, status chan error, } return } + + // Handle CSV format (legacy) + file, err := os.Open(input) + if err != nil { + log.Fatalf("Failed to open file %s%s%s: %s%+v%s", + SourceColor, input, DefaultColor, ErrorColor, err, DefaultColor) + return + } + defer file.Close() + + scanner := bufio.NewScanner(file) + for scanner.Scan() { + line := scanner.Text() + instruction, err := ParseInstruction(line, filepath.Dir(input)) + if err != nil { + log.Printf("Error parsing line: %s'%s'%s, error: %s%+v%s", + SourceColor, line, DefaultColor, ErrorColor, err, DefaultColor) + continue + } + log.Printf("Read instruction: %s", instruction.String()) + output <- &instruction + } } func ReadFromArgs(output chan *LinkInstruction, status chan error) {