Commit f85a951

Richard Luby <richluby@gmail.com>
2016-11-05 07:12:57
fixed user command
user command updated to match command framework
1 parent a94d133
command.go
@@ -40,23 +40,20 @@ var commandArray = []Command{Command{Command: "exit",
 		Run: executeTest},
 	Command{
 		Command: "user",
-		Usage:   "user <username> <token>",
+		Usage:   "user <username>",
 		Flags: map[string]Flag{"username": Flag{Flag: "username",
 			Description: "The username to use for this session",
 			Value:       "anonymous",
 			Usage:       ""}},
-		Description: "Set the user name to utilize during this session. If not set, anonymous will be used." +
-			COLOR_GREEN + " token" + COLOR_RESET + " is a unique, non-secret key to prevent duplicate users from occurring.",
-		Run: setUserName}}
+		Description: "Set the user name to utilize during this session. If not set, anonymous will be used.",
+		Run:         setUserName}}
 
 // sets the user name for this session
 func setUserName(command Command) error {
-	if command.Flags["username"].Value == "" {
+	if len(command.PositionalParameters) < 1 {
 		return fmt.Errorf("Could not set the user due to empty username.")
-	} else if command.Flags[""].Value == "" {
-		return fmt.Errorf("Could not set the user due to the lack of a user token.")
 	}
-	clientConfig.USER = command.Flags["username"].Value
+	clientConfig.USER = command.PositionalParameters[0]
 	return nil
 }
 
@@ -148,7 +145,8 @@ func postRecordsToServer(client *http.Client, recordArray *ClientTest) error {
 }
 
 // getRecordFromServer retrieves a record from the server
-func getRecordFromServer(client *http.Client, config CLIENT_CONFIG, numQuestions int, useBlueprint bool) ([]ClientRecord, error) {
+func getRecordFromServer(client *http.Client, config CLIENT_CONFIG,
+	numQuestions int, useBlueprint bool) ([]ClientRecord, error) {
 	// allows adding configuration for port specific (ie HTTPS) requests
 	resp, err := client.Get(clientConfig.SERVER_URL + API_ROOT + "/test" + "?questions=" + strconv.Itoa(numQuestions))
 	if err != nil {
commandParser.go
@@ -39,7 +39,7 @@ func SelectCommand(str string, commandArray []Command) (Command, error) {
 // expandShortOptions takes condensed short options and
 // expands them into properly formatted short options
 func expandShortOptions(shorts string) []string {
-	var options = make([]string, len(shorts)-1)
+	var options = make([]string, (len(shorts)-1)*2)
 	for char := range shorts {
 		options = append(options, "-"+string(char))
 	}