support max-col-width parameters

support commands:
- helm chart list
- helm dependency list

Signed-off-by: cndoit18 <cndoit18@outlook.com>
pull/9681/head
cndoit18 4 years ago
parent a499b4b179
commit a79cad5539
No known key found for this signature in database
GPG Key ID: A5E54CE7AC730381

@ -31,14 +31,18 @@ Charts are sorted by ref name, alphabetically.
`
func newChartListCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
return &cobra.Command{
chartList := action.NewChartList(cfg)
cmd := &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
Short: "list all saved charts",
Long: chartListDesc,
Hidden: !FeatureGateOCI.IsEnabled(),
RunE: func(cmd *cobra.Command, args []string) error {
return action.NewChartList(cfg).Run(out)
return chartList.Run(out)
},
}
f := cmd.Flags()
f.UintVar(&chartList.ColumnWidth, "max-col-width", 60, "maximum column width for output table")
return cmd
}

@ -100,7 +100,6 @@ func newDependencyCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
func newDependencyListCmd(out io.Writer) *cobra.Command {
client := action.NewDependency()
cmd := &cobra.Command{
Use: "list CHART",
Aliases: []string{"ls"},
@ -115,5 +114,9 @@ func newDependencyListCmd(out io.Writer) *cobra.Command {
return client.List(chartpath, out)
},
}
f := cmd.Flags()
f.UintVar(&client.ColumnWidth, "max-col-width", 80, "maximum column width for output table")
return cmd
}

@ -51,6 +51,7 @@ type (
authorizer *Authorizer
resolver *Resolver
cache *Cache
columnWidth uint
}
)
@ -95,6 +96,10 @@ func NewClient(opts ...ClientOption) (*Client, error) {
}
client.cache = cache
}
if client.columnWidth == 0 {
client.columnWidth = 60
}
return client, nil
}
@ -279,7 +284,7 @@ func (c *Client) RemoveChart(ref *Reference) error {
// PrintChartTable prints a list of locally stored charts
func (c *Client) PrintChartTable() error {
table := uitable.New()
table.MaxColWidth = 60
table.MaxColWidth = c.columnWidth
table.AddRow("REF", "NAME", "VERSION", "DIGEST", "SIZE", "CREATED")
rows, err := c.getChartTableRows()
if err != nil {

@ -67,3 +67,10 @@ func ClientOptCredentialsFile(credentialsFile string) ClientOption {
client.credentialsFile = credentialsFile
}
}
// ClientOptColumnWidth returns a function that sets the column width on a client options set
func ClientOptColumnWidth(columnWidth uint) ClientOption {
return func(client *Client) {
client.columnWidth = columnWidth
}
}

@ -18,11 +18,14 @@ package action
import (
"io"
"helm.sh/helm/v3/internal/experimental/registry"
)
// ChartList performs a chart list operation.
type ChartList struct {
cfg *Configuration
cfg *Configuration
ColumnWidth uint
}
// NewChartList creates a new ChartList object with the given configuration.
@ -34,5 +37,8 @@ func NewChartList(cfg *Configuration) *ChartList {
// Run executes the chart list operation
func (a *ChartList) Run(out io.Writer) error {
return a.cfg.RegistryClient.PrintChartTable()
client := a.cfg.RegistryClient
opt := registry.ClientOptColumnWidth(a.ColumnWidth)
opt(client)
return client.PrintChartTable()
}

@ -37,11 +37,14 @@ type Dependency struct {
Verify bool
Keyring string
SkipRefresh bool
ColumnWidth uint
}
// NewDependency creates a new Dependency object with the given configuration.
func NewDependency() *Dependency {
return &Dependency{}
return &Dependency{
ColumnWidth: 80,
}
}
// List executes 'helm dependency list'.
@ -181,7 +184,7 @@ func statArchiveForStatus(archive string, dep *chart.Dependency) string {
// printDependencies prints all of the dependencies in the yaml file.
func (d *Dependency) printDependencies(chartpath string, out io.Writer, c *chart.Chart) {
table := uitable.New()
table.MaxColWidth = 80
table.MaxColWidth = d.ColumnWidth
table.AddRow("NAME", "VERSION", "REPOSITORY", "STATUS")
for _, row := range c.Metadata.Dependencies {
table.AddRow(row.Name, row.Version, row.Repository, d.dependencyStatus(chartpath, row, c))

Loading…
Cancel
Save