Commit 055e317
Changed files (1)
client.go
@@ -68,22 +68,19 @@ func initUserSession(config CONFIG) {
fmt.Printf("%s", "Welcome to the question interface. Use 'help' for more information.")
for {
var input string
- var commandType int
+ var command Command
var err error
fmt.Printf("\n:> ")
fmt.Scanln(&input)
args := strings.Fields(input)
- if commandType, err = convertToiota(args[0]); err != nil {
- log.Printf("Error while parsing: %+v", err)
+ // select a command from the list of available commands
+ if command, err = selectCommand(strings.TrimSpace(args[0])); err != nil {
+ log.Printf("Error while selecting command: %+v", err)
continue
}
- // loop through available commands and run the correct one
- for _, command := range commandArray {
- if command.Command == commandType {
- if err = command.Run(args[1:]); err != nil {
- log.Printf("Error while executing: %+v", err)
- }
- }
+ // execute the command and check for any errors that may have occurred
+ if err = command.Run(args[1:]); err != nil {
+ log.Printf("Error while executing: %+v", err)
}
}
}