Commit 6386f93
Changed files (2)
client.go
@@ -22,6 +22,8 @@ type CONFIG struct {
PORT int
// USE_HTTPS determines if the client should connect using HTTPS
USE_HTTPS bool
+ // USER defines the user that is in control of this session
+ USER string
}
var config CONFIG
command.go
@@ -13,6 +13,7 @@ import (
type Command struct {
Command string
Description string
+ Usage string
Run func(args []string) error
}
@@ -28,20 +29,36 @@ func selectCommand(str string) (Command, error) {
// commandArray contains the full list of commands available to the application
// note that subcommands are not currently supported
-var commandArray = []Command{Command{Command: "test",
- Description: "Execute a test. Given a number, will go through a test with [n] questions. Type 'exit' to stop test.",
- Run: executeTest},
+var commandArray = []Command{
+ Command{Command: "exit",
+ Description: "Exit the self-assessment application and close the connection.",
+ Run: func(args []string) error {
+ fmt.Print("Exiting application.\n")
+ os.Exit(0)
+ return nil
+ }},
Command{Command: "score",
Description: "Display the score for the user.",
Run: func(args []string) error {
fmt.Print("score was run.")
return nil
}},
- Command{Command: "exit",
- Description: "Exit the self-assessment application and close the connection.",
+ Command{Command: "test",
+ Usage: "test [number]",
+ Description: "Execute a test. Given a number, will go through a test with [n] questions. Type 'exit' to stop test.",
+ Run: executeTest},
+ Command{
+ Command: "user",
+ Usage: "user <username> <token>",
+ Description: "Set the user name to utilize during this session. If not set, anonymous will be used." +
+ "'token' is a unique, non-secret key to prevent duplicate users from occurring.",
Run: func(args []string) error {
- fmt.Print("Exiting application.\n")
- os.Exit(0)
+ if len(args) < 1 {
+ return fmt.Errorf("Could not set the user due to empty username.")
+ } else if len(args) < 2 {
+ return fmt.Errorf("Could not set the user due to the lack of a user token.")
+ }
+ config.USER = args[0]
return nil
}}}
@@ -51,7 +68,11 @@ var helpCommand = Command{Command: "help",
Description: "Display help for all known commands.",
Run: func(args []string) error {
for _, command := range commandArray {
- fmt.Printf("%s\n\t%s\n", command.Command, command.Description)
+ if strings.Compare(command.Usage, "") == 0 {
+ fmt.Printf("%s\n\t%s\n", command.Command, command.Description)
+ } else {
+ fmt.Printf("%s\n\t%s\n", command.Usage, command.Description)
+ }
}
return nil
}}