feat: show customization data when listing/displaying app charts
@@ -2,7 +2,11 @@ package usercmd
import (
"context"
+ "fmt"
+ "sort"
+ "strings"
+ "github.com/epinio/epinio/pkg/api/core/v1/models"
"github.com/fatih/color"
"github.com/pkg/errors"
)
@@ -73,20 +77,23 @@ func (c *EpinioClient) ChartList(ctx context.Context) error {
return err
}
- msg := c.ui.Success().WithTable("Default", "Name", "Created", "Description")
+ msg := c.ui.Success().WithTable("Default", "Name", "Created", "Description", "#Settings")
for _, chart := range charts {
mark := ""
name := chart.Meta.Name
created := chart.Meta.CreatedAt.String()
short := chart.ShortDescription
+ numSettings := fmt.Sprintf(`%d`, len(chart.Settings))
+
if chart.Meta.Name == c.Settings.AppChart {
mark = color.BlueString("*")
name = color.BlueString(name)
created = color.BlueString(created)
short = color.BlueString(short)
+ numSettings = color.BlueString(numSettings)
}
- msg = msg.WithTableRow(mark, name, created, short)
+ msg = msg.WithTableRow(mark, name, created, short, numSettings)
}
msg.Msg("Ok")
@@ -109,7 +116,7 @@ func (c *EpinioClient) ChartShow(ctx context.Context, name string) error {
return err
}
- c.ui.Success().WithTable("Key", "Value").
+ c.ui.Note().WithTable("Key", "Value").
WithTableRow("Name", chart.Meta.Name).
WithTableRow("Created", chart.Meta.CreatedAt.String()).
WithTableRow("Short", chart.ShortDescription).
@@ -118,9 +125,61 @@ func (c *EpinioClient) ChartShow(ctx context.Context, name string) error {
WithTableRow("Helm Chart", chart.HelmChart).
Msg("Details:")
+ if len(chart.Settings) > 0 {
+ var keys []string
+ for key := range chart.Settings {
+ keys = append(keys, key)
+ }
+ sort.Strings(keys)
+
+ msg := c.ui.Note().WithTable("Key", "Type", "Allowed Values")
+
+ for _, key := range keys {
+ spec := chart.Settings[key]
+ msg = msg.WithTableRow(key, spec.Type, details(spec))
+ }
+
+ msg.Msg("Settings")
+ } else {
+ c.ui.Exclamation().Msg("No settings")
+ }
+
+ c.ui.Success().Msg("Ok")
+
return nil
}
+func details(spec models.AppChartSetting) string {
+ // Type expected to be in (string, bool, number, integer)
+ if spec.Type == "bool" {
+ return ""
+ }
+ if spec.Type == "string" {
+ if len(spec.Enum) > 0 {
+ return strings.Join(spec.Enum, ", ")
+ }
+ return ""
+ }
+ if spec.Type == "number" || spec.Type == "integer" {
+ if len(spec.Enum) > 0 {
+ return strings.Join(spec.Enum, ", ")
+ }
+ if spec.Minimum != "" || spec.Maximum != "" {
+ min := "-inf"
+ if spec.Minimum != "" {
+ min = spec.Minimum
+ }
+ max := "+inf"
+ if spec.Maximum != "" {
+ max = spec.Maximum
+ }
+ return fmt.Sprintf(`[%s ... %s]`, min, max)
+ }
+ return ""
+ }
+ return "<unknown type>"
+}
+
// ChartMatching retrieves all application charts in the cluster, for the given prefix
func (c *EpinioClient) ChartMatching(prefix string) []string {
log := c.Log.WithName("ChartMatching")
