提交 6c7cadb3 编写于 作者: M Medya Gh

make minikube addons list tabular

上级 0a9e8b03
......@@ -22,17 +22,17 @@ import (
"os"
"sort"
"strings"
"text/template"
"github.com/golang/glog"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/out"
)
const defaultAddonListFormat = "- {{.AddonName}}: {{.AddonStatus}}\n"
var addonListFormat string
var addonListOutput string
// AddonListTemplate represents the addon list template
......@@ -50,10 +50,6 @@ var addonsListCmd = &cobra.Command{
exit.UsageT("usage: minikube addons list")
}
if addonListOutput != "list" && addonListFormat != defaultAddonListFormat {
exit.UsageT("Cannot use both --output and --format options")
}
switch strings.ToLower(addonListOutput) {
case "list":
printAddonsList()
......@@ -66,14 +62,6 @@ var addonsListCmd = &cobra.Command{
}
func init() {
addonsListCmd.Flags().StringVarP(
&addonListFormat,
"format",
"f",
defaultAddonListFormat,
`Go template format string for the addon list output. The format for Go templates can be found here: https://golang.org/pkg/text/template/
For the list of accessible variables for the template, see the struct values here: https://godoc.org/k8s.io/minikube/cmd/minikube/cmd/config#AddonListTemplate`)
addonsListCmd.Flags().StringVarP(
&addonListOutput,
"output",
......@@ -84,6 +72,13 @@ For the list of accessible variables for the template, see the struct values her
AddonsCmd.AddCommand(addonsListCmd)
}
var iconFromStatus = func(addonStatus bool) string {
if addonStatus {
return "✅"
}
return " " // because emoji indentation is different
}
var stringFromStatus = func(addonStatus bool) string {
if addonStatus {
return "enabled"
......@@ -97,6 +92,13 @@ var printAddonsList = func() {
addonNames = append(addonNames, addonName)
}
sort.Strings(addonNames)
var tData [][]string
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Addon Name", "Profile", "Status"})
table.SetAutoFormatHeaders(true)
table.SetBorders(tablewriter.Border{Left: true, Top: true, Right: true, Bottom: true})
table.SetCenterSeparator("|")
pName := viper.GetString(config.MachineProfile)
for _, addonName := range addonNames {
addonBundle := assets.Addons[addonName]
......@@ -104,20 +106,25 @@ var printAddonsList = func() {
if err != nil {
exit.WithError("Error getting addons status", err)
}
tmpl, err := template.New("list").Parse(addonListFormat)
if err != nil {
exit.WithError("Error creating list template", err)
}
listTmplt := AddonListTemplate{addonName, stringFromStatus(addonStatus)}
err = tmpl.Execute(os.Stdout, listTmplt)
if err != nil {
exit.WithError("Error executing list template", err)
}
tData = append(tData, []string{addonName, pName, fmt.Sprintf("%s %s", stringFromStatus(addonStatus), iconFromStatus(addonStatus))})
}
table.AppendBulk(tData)
table.Render()
v, _, err := config.ListProfiles()
if err != nil {
glog.Infof("error getting list of porfiles: %v", err)
}
if len(v) > 1 {
out.T(out.Tip, "To see addons list for other profiles use: `minikube addons -p name list`")
}
}
var printAddonsJSON = func() {
addonNames := make([]string, 0, len(assets.Addons))
pName := viper.GetString(config.MachineProfile)
for addonName := range assets.Addons {
addonNames = append(addonNames, addonName)
}
......@@ -134,7 +141,8 @@ var printAddonsJSON = func() {
}
addonsMap[addonName] = map[string]interface{}{
"Status": stringFromStatus(addonStatus),
"Status": stringFromStatus(addonStatus),
"Profile": pName,
}
}
jsonString, _ := json.Marshal(addonsMap)
......
......@@ -59,7 +59,6 @@ var profileListCmd = &cobra.Command{
var printProfilesTable = func() {
var validData [][]string
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Profile", "VM Driver", "NodeIP", "Node Port", "Kubernetes Version", "Status"})
table.SetAutoFormatHeaders(false)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册