From 20a21f686d70df62a55f5e083a6cab8fc6a80188 Mon Sep 17 00:00:00 2001 From: karthikv81 <8276827+karthikv81@users.noreply.github.com> Date: Wed, 26 Jun 2019 21:45:08 +0530 Subject: [PATCH] List and set minikube profiles #1716 --- cmd/minikube/cmd/config/profile.go | 36 +++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/cmd/minikube/cmd/config/profile.go b/cmd/minikube/cmd/config/profile.go index 770e5f6bf25d..75a17652f1a0 100644 --- a/cmd/minikube/cmd/config/profile.go +++ b/cmd/minikube/cmd/config/profile.go @@ -18,7 +18,9 @@ package config import ( "os" - + "io/ioutil" + "strings" + "github.com/spf13/cobra" "github.com/spf13/viper" pkgConfig "k8s.io/minikube/pkg/minikube/config" @@ -28,23 +30,45 @@ import ( pkgutil "k8s.io/minikube/pkg/util" ) +var ( + profileList bool + profileSet string +) + + + // ProfileCmd represents the profile command var ProfileCmd = &cobra.Command{ Use: "profile [MINIKUBE_PROFILE_NAME]. You can return to the default minikube profile by running `minikube profile default`", Short: "Profile gets or sets the current minikube profile", Long: "profile sets the current minikube profile, or gets the current profile if no arguments are provided. This is used to run and manage multiple minikube instance. You can return to the default minikube profile by running `minikube profile default`", Run: func(cmd *cobra.Command, args []string) { - if len(args) == 0 { + if profileList { + var profilePathStr strings.Builder + profilePathStr.WriteString(constants.GetMinipath()) + profilePathStr.WriteString("/profiles") + files, err := ioutil.ReadDir(profilePathStr.String()) + if err != nil { + exit.WithError("Getting profile failed", err) + } + console.OutLn("Available profiles are:") + for _,file := range files { + console.OutLn("%s", file.Name()) + } + os.Exit(0) + } + + if (profileSet == "") && (len(args) == 0) { profile := viper.GetString(pkgConfig.MachineProfile) - console.OutLn("%s", profile) + console.OutLn("Current Profile: %s", profile) os.Exit(0) } - if len(args) > 1 { - exit.Usage("usage: minikube profile [MINIKUBE_PROFILE_NAME]") + if ((profileSet != "") && (len(args) > 1)) { + exit.Usage("usage: minikube profile -l | -s [MINIKUBE_PROFILE_NAME] ") } - profile := args[0] + profile := profileSet if profile == "default" { profile = "minikube" }