Make kubectl commands return errors and centralize exit handling

This commit is contained in:
Jeff Lowdermilk
2015-03-09 15:08:16 -07:00
parent 7b72d9539f
commit cd7d78b696
20 changed files with 875 additions and 644 deletions

View File

@@ -30,17 +30,25 @@ func (f *Factory) NewCmdVersion(out io.Writer) *cobra.Command {
Use: "version",
Short: "Print the client and server version information.",
Run: func(cmd *cobra.Command, args []string) {
if util.GetFlagBool(cmd, "client") {
kubectl.GetClientVersion(out)
return
}
client, err := f.Client(cmd)
err := RunVersion(f, out, cmd)
util.CheckErr(err)
kubectl.GetVersion(out, client)
},
}
cmd.Flags().BoolP("client", "c", false, "Client version only (no server required).")
return cmd
}
func RunVersion(f *Factory, out io.Writer, cmd *cobra.Command) error {
if util.GetFlagBool(cmd, "client") {
kubectl.GetClientVersion(out)
return nil
}
client, err := f.Client(cmd)
if err != nil {
return err
}
kubectl.GetVersion(out, client)
return nil
}