mirror of
https://github.com/on4kjm/FLEcli.git
synced 2025-01-18 13:01:09 +01:00
Read the file in a string array
This commit is contained in:
parent
dc68ad5301
commit
0250079d37
3 changed files with 30 additions and 2 deletions
27
cmd/load.go
27
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)
|
||||
}
|
||||
}
|
3
test/commands.md
Normal file
3
test/commands.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Commands for testing
|
||||
|
||||
* `./FLEcli -i test/data/fle-1.txt load`
|
2
todo.md
2
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
|
||||
|
|
Loading…
Reference in a new issue