cmd/internal: request lowercase access name

Viper has a feature/bug where all YAML config keys are cast
to lowercase (see https://github.com/spf13/viper/issues/260
and https://github.com/spf13/viper/issues/411).
Since we use Viper to load our config values, it doesn't seem
like there's an easy way to preserve case sensitivity for the
access names chosen by users right now. Adding this prompt
should help user experience by clarifying that all access
names must be lowercase.

Change-Id: I47e8344bb0ca7e78458405496f20e78e3c9f9a88
This commit is contained in:
Natalie Villasana 2020-05-18 22:56:53 -04:00 committed by Ivan Fraixedes
parent 6fac1ed130
commit c7cbdcbccf

View File

@ -8,6 +8,7 @@ import (
"fmt"
"net"
"os"
"strings"
"github.com/spf13/cobra"
"github.com/zeebo/errs"
@ -18,7 +19,7 @@ import (
// PromptForAccessName handles user input for access name to be used with wizards
func PromptForAccessName() (string, error) {
_, err := fmt.Printf("Choose an access name [\"default\"]: ")
_, err := fmt.Printf("Choose an access name (use lowercase letters) [\"default\"]: ")
if err != nil {
return "", err
}
@ -32,6 +33,11 @@ func PromptForAccessName() (string, error) {
if accessName == "" {
return "default", nil
}
if accessName != strings.ToLower(accessName) {
return "", errs.New("Please only use lowercase letters for access name.")
}
return accessName, nil
}