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
pull/2836/head
xuhaigang 8 years ago committed by 徐海刚
parent fa06dd176d
commit eddf81bf0c

@ -50,6 +50,7 @@ type historyCmd struct {
rls string rls string
out io.Writer out io.Writer
helmc helm.Interface helmc helm.Interface
output string
} }
func newHistoryCmd(c helm.Interface, w io.Writer) *cobra.Command { func newHistoryCmd(c helm.Interface, w io.Writer) *cobra.Command {
@ -73,7 +74,9 @@ func newHistoryCmd(c helm.Interface, w io.Writer) *cobra.Command {
}, },
} }
cmd.Flags().Int32Var(&his.max, "max", 256, "maximum number of revision to include in history") 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")
return cmd return cmd
} }
@ -87,13 +90,19 @@ func (cmd *historyCmd) run() error {
return nil return nil
} }
fmt.Fprintln(cmd.out, formatHistory(r.Releases)) fmt.Fprintln(cmd.out, formatHistory(r.Releases, cmd.output))
return nil return nil
} }
func formatHistory(rls []*release.Release) string { func formatHistory(rls []*release.Release, output string) string {
tbl := uitable.New() tbl := uitable.New()
switch output {
case "wide":
break
default:
tbl.MaxColWidth = 60 tbl.MaxColWidth = 60
}
tbl.AddRow("REVISION", "UPDATED", "STATUS", "CHART", "DESCRIPTION") tbl.AddRow("REVISION", "UPDATED", "STATUS", "CHART", "DESCRIPTION")
for i := len(rls) - 1; i >= 0; i-- { for i := len(rls) - 1; i >= 0; i-- {
r := rls[i] r := rls[i]

@ -74,6 +74,7 @@ type listCmd struct {
superseded bool superseded bool
pending bool pending bool
client helm.Interface client helm.Interface
output string
} }
func newListCmd(client helm.Interface, out io.Writer) *cobra.Command { func newListCmd(client helm.Interface, out io.Writer) *cobra.Command {
@ -112,6 +113,7 @@ func newListCmd(client helm.Interface, out io.Writer) *cobra.Command {
f.BoolVar(&list.failed, "failed", false, "show failed releases") f.BoolVar(&list.failed, "failed", false, "show failed releases")
f.BoolVar(&list.pending, "pending", false, "show pending releases") f.BoolVar(&list.pending, "pending", false, "show pending releases")
f.StringVar(&list.namespace, "namespace", "", "show releases within a specific namespace") f.StringVar(&list.namespace, "namespace", "", "show releases within a specific namespace")
f.StringVar(&list.output, "output", "short", "specifies the output format")
// TODO: Do we want this as a feature of 'helm list'? // TODO: Do we want this as a feature of 'helm list'?
//f.BoolVar(&list.superseded, "history", true, "show historical releases") //f.BoolVar(&list.superseded, "history", true, "show historical releases")
@ -162,7 +164,7 @@ func (l *listCmd) run() error {
} }
return nil return nil
} }
fmt.Fprintln(l.out, formatList(rels)) fmt.Fprintln(l.out, formatList(rels, l.output))
return nil return nil
} }
@ -207,9 +209,15 @@ func (l *listCmd) statusCodes() []release.Status_Code {
return status return status
} }
func formatList(rels []*release.Release) string { func formatList(rels []*release.Release, output string) string {
table := uitable.New() table := uitable.New()
switch output {
case "wide":
break
default:
table.MaxColWidth = 60 table.MaxColWidth = 60
}
table.AddRow("NAME", "REVISION", "UPDATED", "STATUS", "CHART", "NAMESPACE") table.AddRow("NAME", "REVISION", "UPDATED", "STATUS", "CHART", "NAMESPACE")
for _, r := range rels { for _, r := range rels {
c := fmt.Sprintf("%s-%s", r.Chart.Metadata.Name, r.Chart.Metadata.Version) c := fmt.Sprintf("%s-%s", r.Chart.Metadata.Name, r.Chart.Metadata.Version)

@ -29,6 +29,7 @@ helm history [flags] RELEASE_NAME
``` ```
--max int32 maximum number of revision to include in history (default 256) --max int32 maximum number of revision to include in history (default 256)
--output string specifies the output format (default "short")
--tls enable TLS for request --tls enable TLS for request
--tls-ca-cert string path to TLS CA certificate file (default "$HELM_HOME/ca.pem") --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") --tls-cert string path to TLS certificate file (default "$HELM_HOME/cert.pem")
@ -50,4 +51,4 @@ helm history [flags] RELEASE_NAME
### SEE ALSO ### SEE ALSO
* [helm](helm.md) - The Helm package manager for Kubernetes. * [helm](helm.md) - The Helm package manager for Kubernetes.
###### Auto generated by spf13/cobra on 7-Nov-2017 ###### Auto generated by spf13/cobra on 10-Jan-2018

@ -48,6 +48,7 @@ helm list [flags] [FILTER]
-m, --max int maximum number of releases to fetch (default 256) -m, --max int maximum number of releases to fetch (default 256)
--namespace string show releases within a specific namespace --namespace string show releases within a specific namespace
-o, --offset string next release name in the list, used to offset from start value -o, --offset string next release name in the list, used to offset from start value
--output string specifies the output format (default "short")
--pending show pending releases --pending show pending releases
-r, --reverse reverse the sort order -r, --reverse reverse the sort order
-q, --short output short (quiet) listing format -q, --short output short (quiet) listing format
@ -72,4 +73,4 @@ helm list [flags] [FILTER]
### SEE ALSO ### SEE ALSO
* [helm](helm.md) - The Helm package manager for Kubernetes. * [helm](helm.md) - The Helm package manager for Kubernetes.
###### Auto generated by spf13/cobra on 7-Nov-2017 ###### Auto generated by spf13/cobra on 10-Jan-2018

Loading…
Cancel
Save