Improve message from kubectl config

1.use Fprintf instead of Printf
2.output simple success messages
3.lowercase all error messages
This commit is contained in:
hurf
2015-09-23 16:08:42 +08:00
parent 45a8b5f98a
commit c4dc056105
11 changed files with 45 additions and 33 deletions

View File

@@ -84,6 +84,8 @@ func NewCmdConfigSetAuthInfo(out io.Writer, configAccess ConfigAccess) *cobra.Co
err := options.run()
if err != nil {
fmt.Fprintf(out, "%v\n", err)
} else {
fmt.Fprintf(out, "user %q set.\n", options.name)
}
},
}
@@ -197,7 +199,7 @@ func (o *createAuthInfoOptions) complete(cmd *cobra.Command) bool {
func (o createAuthInfoOptions) validate() error {
if len(o.name) == 0 {
return errors.New("You must specify a non-empty user name")
return errors.New("you must specify a non-empty user name")
}
methods := []string{}
if len(o.token.Value()) > 0 {
@@ -207,22 +209,22 @@ func (o createAuthInfoOptions) validate() error {
methods = append(methods, fmt.Sprintf("--%v/--%v", clientcmd.FlagUsername, clientcmd.FlagPassword))
}
if len(methods) > 1 {
return fmt.Errorf("You cannot specify more than one authentication method at the same time: %v", strings.Join(methods, ", "))
return fmt.Errorf("you cannot specify more than one authentication method at the same time: %v", strings.Join(methods, ", "))
}
if o.embedCertData.Value() {
certPath := o.clientCertificate.Value()
keyPath := o.clientKey.Value()
if certPath == "" && keyPath == "" {
return fmt.Errorf("You must specify a --%s or --%s to embed", clientcmd.FlagCertFile, clientcmd.FlagKeyFile)
return fmt.Errorf("you must specify a --%s or --%s to embed", clientcmd.FlagCertFile, clientcmd.FlagKeyFile)
}
if certPath != "" {
if _, err := ioutil.ReadFile(certPath); err != nil {
return fmt.Errorf("Error reading %s data from %s: %v", clientcmd.FlagCertFile, certPath, err)
return fmt.Errorf("error reading %s data from %s: %v", clientcmd.FlagCertFile, certPath, err)
}
}
if keyPath != "" {
if _, err := ioutil.ReadFile(keyPath); err != nil {
return fmt.Errorf("Error reading %s data from %s: %v", clientcmd.FlagKeyFile, keyPath, err)
return fmt.Errorf("error reading %s data from %s: %v", clientcmd.FlagKeyFile, keyPath, err)
}
}
}