From 056b94e88d5a9298e7826521ae14ae4429d3622a Mon Sep 17 00:00:00 2001 From: rocky-nupt Date: Fri, 20 Oct 2017 10:41:27 +0800 Subject: [PATCH] feat(helm): Add --full-output to helm list and helm history The default maximum length of the output table is 60 chars. When the length is greater than 60, the content will be omitted. This patch adds -f and --full-output to helm list and helm history which can display full information of releases on the screen. Closes #2828 --- cmd/helm/history.go | 23 +++++++++-------------- cmd/helm/list.go | 15 +++++---------- docs/helm/helm_history.md | 2 +- docs/helm/helm_list.md | 2 +- 4 files changed, 16 insertions(+), 26 deletions(-) diff --git a/cmd/helm/history.go b/cmd/helm/history.go index 43d188a3b..0637eca64 100644 --- a/cmd/helm/history.go +++ b/cmd/helm/history.go @@ -46,11 +46,11 @@ The historical release set is printed as a formatted table, e.g: ` type historyCmd struct { - max int32 - rls string - out io.Writer - helmc helm.Interface - output string + max int32 + rls string + out io.Writer + helmc helm.Interface + colWidth uint } func newHistoryCmd(c helm.Interface, w io.Writer) *cobra.Command { @@ -76,7 +76,7 @@ func newHistoryCmd(c helm.Interface, w io.Writer) *cobra.Command { f := cmd.Flags() f.Int32Var(&his.max, "max", 256, "maximum number of revision to include in history") - f.StringVar(&his.output, "output", "short", "specifies the output format: short|wide") + f.UintVar(&his.colWidth, "col-width", 60, "specifies the max column width of output") return cmd } @@ -90,19 +90,14 @@ func (cmd *historyCmd) run() error { return nil } - fmt.Fprintln(cmd.out, formatHistory(r.Releases, cmd.output)) + fmt.Fprintln(cmd.out, formatHistory(r.Releases, cmd.colWidth)) return nil } -func formatHistory(rls []*release.Release, output string) string { +func formatHistory(rls []*release.Release, colWidth uint) string { tbl := uitable.New() - switch output { - case "wide": - break - default: - tbl.MaxColWidth = 60 - } + tbl.MaxColWidth = colWidth tbl.AddRow("REVISION", "UPDATED", "STATUS", "CHART", "DESCRIPTION") for i := len(rls) - 1; i >= 0; i-- { r := rls[i] diff --git a/cmd/helm/list.go b/cmd/helm/list.go index 99cd8f6d0..2666893e8 100644 --- a/cmd/helm/list.go +++ b/cmd/helm/list.go @@ -74,7 +74,7 @@ type listCmd struct { superseded bool pending bool client helm.Interface - output string + colWidth uint } func newListCmd(client helm.Interface, out io.Writer) *cobra.Command { @@ -113,7 +113,7 @@ func newListCmd(client helm.Interface, out io.Writer) *cobra.Command { f.BoolVar(&list.failed, "failed", false, "show failed releases") f.BoolVar(&list.pending, "pending", false, "show pending releases") f.StringVar(&list.namespace, "namespace", "", "show releases within a specific namespace") - f.StringVar(&list.output, "output", "short", "specifies the output format: short|wide") + f.UintVar(&list.colWidth, "col-width", 60, "specifies the max column width of output") // TODO: Do we want this as a feature of 'helm list'? //f.BoolVar(&list.superseded, "history", true, "show historical releases") @@ -164,7 +164,7 @@ func (l *listCmd) run() error { } return nil } - fmt.Fprintln(l.out, formatList(rels, l.output)) + fmt.Fprintln(l.out, formatList(rels, l.colWidth)) return nil } @@ -209,15 +209,10 @@ func (l *listCmd) statusCodes() []release.Status_Code { return status } -func formatList(rels []*release.Release, output string) string { +func formatList(rels []*release.Release, colWidth uint) string { table := uitable.New() - switch output { - case "wide": - break - default: - table.MaxColWidth = 60 - } + table.MaxColWidth = colWidth table.AddRow("NAME", "REVISION", "UPDATED", "STATUS", "CHART", "NAMESPACE") for _, r := range rels { c := fmt.Sprintf("%s-%s", r.Chart.Metadata.Name, r.Chart.Metadata.Version) diff --git a/docs/helm/helm_history.md b/docs/helm/helm_history.md index 23c8a6c11..d9edd85c0 100755 --- a/docs/helm/helm_history.md +++ b/docs/helm/helm_history.md @@ -28,8 +28,8 @@ helm history [flags] RELEASE_NAME ### Options ``` + --col-width uint specifies the max column width of output (default 60) --max int32 maximum number of revision to include in history (default 256) - --output string specifies the output format: short|wide (default "short") --tls enable TLS for request --tls-ca-cert string path to TLS CA certificate file (default "$HELM_HOME/ca.pem") --tls-cert string path to TLS certificate file (default "$HELM_HOME/cert.pem") diff --git a/docs/helm/helm_list.md b/docs/helm/helm_list.md index f18b31f39..733655cb8 100755 --- a/docs/helm/helm_list.md +++ b/docs/helm/helm_list.md @@ -40,6 +40,7 @@ helm list [flags] [FILTER] ``` -a, --all show all releases, not just the ones marked DEPLOYED + --col-width uint specifies the max column width of output (default 60) -d, --date sort by release date --deleted show deleted releases --deleting show releases that are currently being deleted @@ -48,7 +49,6 @@ helm list [flags] [FILTER] -m, --max int maximum number of releases to fetch (default 256) --namespace string show releases within a specific namespace -o, --offset string next release name in the list, used to offset from start value - --output string specifies the output format: short|wide (default "short") --pending show pending releases -r, --reverse reverse the sort order -q, --short output short (quiet) listing format