Merge pull request #9681 from cndoit18/add-max-col-width-parameters

support max-col-width parameters
pull/9746/head
Martin Hickey 4 years ago committed by GitHub
commit 599c071ac7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -31,14 +31,18 @@ Charts are sorted by ref name, alphabetically.
` `
func newChartListCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { func newChartListCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
return &cobra.Command{ chartList := action.NewChartList(cfg)
cmd := &cobra.Command{
Use: "list", Use: "list",
Aliases: []string{"ls"}, Aliases: []string{"ls"},
Short: "list all saved charts", Short: "list all saved charts",
Long: chartListDesc, Long: chartListDesc,
Hidden: !FeatureGateOCI.IsEnabled(), Hidden: !FeatureGateOCI.IsEnabled(),
RunE: func(cmd *cobra.Command, args []string) error { 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 { func newDependencyListCmd(out io.Writer) *cobra.Command {
client := action.NewDependency() client := action.NewDependency()
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "list CHART", Use: "list CHART",
Aliases: []string{"ls"}, Aliases: []string{"ls"},
@ -115,5 +114,9 @@ func newDependencyListCmd(out io.Writer) *cobra.Command {
return client.List(chartpath, out) return client.List(chartpath, out)
}, },
} }
f := cmd.Flags()
f.UintVar(&client.ColumnWidth, "max-col-width", 80, "maximum column width for output table")
return cmd return cmd
} }

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

@ -67,3 +67,10 @@ func ClientOptCredentialsFile(credentialsFile string) ClientOption {
client.credentialsFile = credentialsFile 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 ( import (
"io" "io"
"helm.sh/helm/v3/internal/experimental/registry"
) )
// ChartList performs a chart list operation. // ChartList performs a chart list operation.
type ChartList struct { type ChartList struct {
cfg *Configuration cfg *Configuration
ColumnWidth uint
} }
// NewChartList creates a new ChartList object with the given configuration. // 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 // Run executes the chart list operation
func (a *ChartList) Run(out io.Writer) error { 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 Verify bool
Keyring string Keyring string
SkipRefresh bool SkipRefresh bool
ColumnWidth uint
} }
// NewDependency creates a new Dependency object with the given configuration. // NewDependency creates a new Dependency object with the given configuration.
func NewDependency() *Dependency { func NewDependency() *Dependency {
return &Dependency{} return &Dependency{
ColumnWidth: 80,
}
} }
// List executes 'helm dependency list'. // 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. // printDependencies prints all of the dependencies in the yaml file.
func (d *Dependency) printDependencies(chartpath string, out io.Writer, c *chart.Chart) { func (d *Dependency) printDependencies(chartpath string, out io.Writer, c *chart.Chart) {
table := uitable.New() table := uitable.New()
table.MaxColWidth = 80 table.MaxColWidth = d.ColumnWidth
table.AddRow("NAME", "VERSION", "REPOSITORY", "STATUS") table.AddRow("NAME", "VERSION", "REPOSITORY", "STATUS")
for _, row := range c.Metadata.Dependencies { for _, row := range c.Metadata.Dependencies {
table.AddRow(row.Name, row.Version, row.Repository, d.dependencyStatus(chartpath, row, c)) table.AddRow(row.Name, row.Version, row.Repository, d.dependencyStatus(chartpath, row, c))

Loading…
Cancel
Save