Skip to content

Commit

Permalink
Merge pull request #1 from karthikv81/karthikv81-patch-minikube-profi…
Browse files Browse the repository at this point in the history
…le-list

List and set minikube profiles kubernetes#1716
  • Loading branch information
karthikv81 authored Jun 26, 2019
2 parents 17a407d + 20a21f6 commit 8bc8ff2
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions cmd/minikube/cmd/config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
}
Expand Down

0 comments on commit 8bc8ff2

Please sign in to comment.