Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement options for the minikube version command #7325

Merged
merged 2 commits into from
Apr 1, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions cmd/minikube/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,55 @@ limitations under the License.
package cmd

import (
"encoding/json"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/version"
)

var (
versionOutput string
shortVersion bool
)

var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version of minikube",
Long: `Print the version of minikube.`,
Run: func(command *cobra.Command, args []string) {
out.Ln("minikube version: %v", version.GetVersion())
minikubeVersion := version.GetVersion()
gitCommitID := version.GetGitCommitID()
if gitCommitID != "" {
out.Ln("commit: %v", gitCommitID)
data := map[string]string{
"minikubeVersion": minikubeVersion,
"commit": gitCommitID,
}
switch versionOutput {
case "":
out.Ln("minikube version: %v", minikubeVersion)
if !shortVersion && gitCommitID != "" {
out.Ln("commit: %v", gitCommitID)
}
case "json":
json, err := json.Marshal(data)
if err != nil {
exit.WithError("version json failure", err)
}
out.Ln(string(json))
case "yaml":
yaml, err := yaml.Marshal(data)
if err != nil {
exit.WithError("version yaml failure", err)
}
out.Ln(string(yaml))
default:
exit.WithCodeT(exit.BadUsage, "error: --output must be 'yaml' or 'json'")
}
},
}

func init() {
versionCmd.Flags().StringVarP(&versionOutput, "output", "o", "", "One of 'yaml' or 'json'.")
versionCmd.Flags().BoolVar(&shortVersion, "short", false, "Print just the version number.")
}