From 0250079d379c513c3a44f8704df4c73f66f96a12 Mon Sep 17 00:00:00 2001 From: Jean-Marc MEESSEN Date: Fri, 29 May 2020 22:39:23 +0200 Subject: [PATCH] Read the file in a string array --- cmd/load.go | 27 ++++++++++++++++++++++++++- test/commands.md | 3 +++ todo.md | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 test/commands.md diff --git a/cmd/load.go b/cmd/load.go index 7faeba0..0808b84 100644 --- a/cmd/load.go +++ b/cmd/load.go @@ -17,8 +17,10 @@ limitations under the License. import ( "fmt" - "github.com/spf13/cobra" + "bufio" + "log" + "os" ) // loadCmd represents the load command @@ -34,6 +36,7 @@ var loadCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { fmt.Println("load called") fmt.Println("Inputfile: ",inputFilename) + loadFile() }, } @@ -50,3 +53,25 @@ func init() { // is called directly, e.g.: // loadCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } + +func loadFile() { + file, err := os.Open(inputFilename) + + if err != nil { + log.Fatalf("failed opening file: %s", err) + } + + scanner := bufio.NewScanner(file) + scanner.Split(bufio.ScanLines) + var txtlines []string + + for scanner.Scan() { + txtlines = append(txtlines, scanner.Text()) + } + + file.Close() + + for _, eachline := range txtlines { + fmt.Println(eachline) + } +} \ No newline at end of file diff --git a/test/commands.md b/test/commands.md new file mode 100644 index 0000000..cb0163d --- /dev/null +++ b/test/commands.md @@ -0,0 +1,3 @@ +# Commands for testing + +* `./FLEcli -i test/data/fle-1.txt load` \ No newline at end of file diff --git a/todo.md b/todo.md index bfb0bcd..93a5cfc 100644 --- a/todo.md +++ b/todo.md @@ -11,7 +11,7 @@ ## Input processing -* [ ] Read the file into array +* [x] Read the file into array * [ ] Parse every line * [ ] Load structured data * [ ] Create structured data storage