Read the file in a string array

pull/2/head
Jean-Marc MEESSEN 5 years ago
parent dc68ad5301
commit 0250079d37

@ -17,8 +17,10 @@ limitations under the License.
import ( import (
"fmt" "fmt"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"bufio"
"log"
"os"
) )
// loadCmd represents the load command // loadCmd represents the load command
@ -34,6 +36,7 @@ var loadCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
fmt.Println("load called") fmt.Println("load called")
fmt.Println("Inputfile: ",inputFilename) fmt.Println("Inputfile: ",inputFilename)
loadFile()
}, },
} }
@ -50,3 +53,25 @@ func init() {
// is called directly, e.g.: // is called directly, e.g.:
// loadCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") // 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)
}
}

@ -0,0 +1,3 @@
# Commands for testing
* `./FLEcli -i test/data/fle-1.txt load`

@ -11,7 +11,7 @@
## Input processing ## Input processing
* [ ] Read the file into array * [x] Read the file into array
* [ ] Parse every line * [ ] Parse every line
* [ ] Load structured data * [ ] Load structured data
* [ ] Create structured data storage * [ ] Create structured data storage

Loading…
Cancel
Save