Commit 32e8584

Richard Luby <richluby@gmail.com>
2016-10-27 11:49:18
test now runs a test
test retrieves questions from the server as the user answers them
1 parent 055e317
Changed files (1)
client.go
@@ -1,6 +1,7 @@
 package main
 
 import (
+	"bufio"
 	"encoding/json"
 	"flag"
 	"fmt"
@@ -23,10 +24,11 @@ type CONFIG struct {
 	USE_HTTPS bool
 }
 
+var config CONFIG
+
 // loadClientConfiguration loads the configuration for the client using the given string
 func loadClientConfiguration(cfgFile string) CONFIG {
 	log.Printf("Loading configuration from %s.", cfgFile)
-	var config CONFIG
 	config.SERVER = "127.0.0.1"
 	config.PORT = 8080
 	config.USE_HTTPS = false
@@ -63,15 +65,16 @@ func getRecordFromServer(client *http.Client, config CONFIG) (Record, error) {
 }
 
 // initUserSession starts the interactive prompt for the user
-func initUserSession(config CONFIG) {
+func initUserSession() {
 	//client := &http.Client{}
 	fmt.Printf("%s", "Welcome to the question interface. Use 'help' for more information.")
+	var input string
+	var command Command
+	var err error
+	reader := bufio.NewReader(os.Stdin)
 	for {
-		var input string
-		var command Command
-		var err error
 		fmt.Printf("\n:> ")
-		fmt.Scanln(&input)
+		input, _ = reader.ReadString('\n')
 		args := strings.Fields(input)
 		// select a command from the list of available commands
 		if command, err = selectCommand(strings.TrimSpace(args[0])); err != nil {
@@ -89,10 +92,9 @@ func initUserSession(config CONFIG) {
 func main() {
 	filePath := flag.String("file", "", "defines a path to the configuration file")
 	flag.Parse()
-	var config CONFIG
 	if strings.Compare(*filePath, "") != 0 {
 		config = loadClientConfiguration(*filePath)
 	}
 	log.Printf("Configuration: %+v", config)
-	initUserSession(config)
+	initUserSession()
 }