mirror of
https://github.com/helm/helm.git
synced 2026-04-28 09:38:45 -04:00
feat(comp): Support completion for --revision flag
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
This commit is contained in:
parent
de1ca6784a
commit
d5d741dfed
7 changed files with 63 additions and 2 deletions
|
|
@ -67,6 +67,14 @@ func newGetAllCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
|
|||
|
||||
f := cmd.Flags()
|
||||
f.IntVar(&client.Version, "revision", 0, "get the named release with revision")
|
||||
flag := f.Lookup("revision")
|
||||
completion.RegisterFlagCompletionFunc(flag, func(cmd *cobra.Command, args []string, toComplete string) ([]string, completion.BashCompDirective) {
|
||||
if len(args) == 1 {
|
||||
return compListRevisions(cfg, args[0])
|
||||
}
|
||||
return nil, completion.BashCompDirectiveNoFileComp
|
||||
})
|
||||
|
||||
f.StringVar(&template, "template", "", "go template for formatting the output, eg: {{.Release.Name}}")
|
||||
|
||||
return cmd
|
||||
|
|
|
|||
|
|
@ -61,7 +61,15 @@ func newGetHooksCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
|
|||
return compListReleases(toComplete, cfg)
|
||||
})
|
||||
|
||||
cmd.Flags().IntVar(&client.Version, "revision", 0, "get the named release with revision")
|
||||
f := cmd.Flags()
|
||||
f.IntVar(&client.Version, "revision", 0, "get the named release with revision")
|
||||
flag := f.Lookup("revision")
|
||||
completion.RegisterFlagCompletionFunc(flag, func(cmd *cobra.Command, args []string, toComplete string) ([]string, completion.BashCompDirective) {
|
||||
if len(args) == 1 {
|
||||
return compListRevisions(cfg, args[0])
|
||||
}
|
||||
return nil, completion.BashCompDirectiveNoFileComp
|
||||
})
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,15 @@ func newGetManifestCmd(cfg *action.Configuration, out io.Writer) *cobra.Command
|
|||
return compListReleases(toComplete, cfg)
|
||||
})
|
||||
|
||||
cmd.Flags().IntVar(&client.Version, "revision", 0, "get the named release with revision")
|
||||
f := cmd.Flags()
|
||||
f.IntVar(&client.Version, "revision", 0, "get the named release with revision")
|
||||
flag := f.Lookup("revision")
|
||||
completion.RegisterFlagCompletionFunc(flag, func(cmd *cobra.Command, args []string, toComplete string) ([]string, completion.BashCompDirective) {
|
||||
if len(args) == 1 {
|
||||
return compListRevisions(cfg, args[0])
|
||||
}
|
||||
return nil, completion.BashCompDirectiveNoFileComp
|
||||
})
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,6 +61,13 @@ func newGetNotesCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
|
|||
|
||||
f := cmd.Flags()
|
||||
f.IntVar(&client.Version, "revision", 0, "get the named release with revision")
|
||||
flag := f.Lookup("revision")
|
||||
completion.RegisterFlagCompletionFunc(flag, func(cmd *cobra.Command, args []string, toComplete string) ([]string, completion.BashCompDirective) {
|
||||
if len(args) == 1 {
|
||||
return compListRevisions(cfg, args[0])
|
||||
}
|
||||
return nil, completion.BashCompDirectiveNoFileComp
|
||||
})
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,13 @@ func newGetValuesCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
|
|||
|
||||
f := cmd.Flags()
|
||||
f.IntVar(&client.Version, "revision", 0, "get the named release with revision")
|
||||
flag := f.Lookup("revision")
|
||||
completion.RegisterFlagCompletionFunc(flag, func(cmd *cobra.Command, args []string, toComplete string) ([]string, completion.BashCompDirective) {
|
||||
if len(args) == 1 {
|
||||
return compListRevisions(cfg, args[0])
|
||||
}
|
||||
return nil, completion.BashCompDirectiveNoFileComp
|
||||
})
|
||||
f.BoolVarP(&client.AllValues, "all", "a", false, "dump all (computed) values")
|
||||
bindOutputFlag(cmd, &outfmt)
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gosuri/uitable"
|
||||
|
|
@ -185,3 +186,16 @@ func min(x, y int) int {
|
|||
}
|
||||
return y
|
||||
}
|
||||
|
||||
func compListRevisions(cfg *action.Configuration, releaseName string) ([]string, completion.BashCompDirective) {
|
||||
client := action.NewHistory(cfg)
|
||||
|
||||
var revisions []string
|
||||
if hist, err := client.Run(releaseName); err == nil {
|
||||
for _, release := range hist {
|
||||
revisions = append(revisions, strconv.Itoa(release.Version))
|
||||
}
|
||||
return revisions, completion.BashCompDirectiveDefault
|
||||
}
|
||||
return nil, completion.BashCompDirectiveError
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,7 +75,16 @@ func newStatusCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
|
|||
})
|
||||
|
||||
f := cmd.PersistentFlags()
|
||||
|
||||
f.IntVar(&client.Version, "revision", 0, "if set, display the status of the named release with revision")
|
||||
flag := f.Lookup("revision")
|
||||
completion.RegisterFlagCompletionFunc(flag, func(cmd *cobra.Command, args []string, toComplete string) ([]string, completion.BashCompDirective) {
|
||||
if len(args) == 1 {
|
||||
return compListRevisions(cfg, args[0])
|
||||
}
|
||||
return nil, completion.BashCompDirectiveNoFileComp
|
||||
})
|
||||
|
||||
bindOutputFlag(cmd, &outfmt)
|
||||
|
||||
return cmd
|
||||
|
|
|
|||
Loading…
Reference in a new issue