From 4a93ea836fe8e2221fbd4eecfeb66fea3b490682 Mon Sep 17 00:00:00 2001 From: Amaury Guillermin Date: Mon, 15 Jun 2020 19:31:17 +0200 Subject: [PATCH] Fixing at runtime eol char --- cmd/airtable-convertor/lib/interation.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/cmd/airtable-convertor/lib/interation.go b/cmd/airtable-convertor/lib/interation.go index f8ee442..83d1219 100644 --- a/cmd/airtable-convertor/lib/interation.go +++ b/cmd/airtable-convertor/lib/interation.go @@ -3,8 +3,10 @@ package lib import ( "bufio" "fmt" + "log" "os" "path/filepath" + "runtime" "strings" ) @@ -30,9 +32,21 @@ func (i *Interaction) AskForInput() string { fmt.Println("Enter the path to file:") reader := bufio.NewReader(i.Input) - input, _ := reader.ReadString('\n') + input, err := reader.ReadString('\n') - return filepath.Join(cwd, strings.ReplaceAll(input, "\n", "")) + if err != nil { + log.Fatal(err) + } + + var newInput string + + if runtime.GOOS == "windows" { + newInput = strings.ReplaceAll(input, "\r\n", "") + } else { + newInput = strings.ReplaceAll(input, "\n", "") + } + + return filepath.Join(cwd, newInput) } // Notify is a commun func to log some actions taken by the script