feat(comp): Support completion for --revision flag

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
pull/7323/head
Marc Khouzam 5 years ago
parent de1ca6784a
commit d5d741dfed

@ -67,6 +67,14 @@ func newGetAllCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
f := cmd.Flags() f := cmd.Flags()
f.IntVar(&client.Version, "revision", 0, "get the named release with revision") 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}}") f.StringVar(&template, "template", "", "go template for formatting the output, eg: {{.Release.Name}}")
return cmd return cmd

@ -61,7 +61,15 @@ func newGetHooksCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
return compListReleases(toComplete, cfg) 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 return cmd
} }

@ -61,7 +61,15 @@ func newGetManifestCmd(cfg *action.Configuration, out io.Writer) *cobra.Command
return compListReleases(toComplete, cfg) 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 return cmd
} }

@ -61,6 +61,13 @@ func newGetNotesCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
f := cmd.Flags() f := cmd.Flags()
f.IntVar(&client.Version, "revision", 0, "get the named release with revision") 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 return cmd
} }

@ -65,6 +65,13 @@ func newGetValuesCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
f := cmd.Flags() f := cmd.Flags()
f.IntVar(&client.Version, "revision", 0, "get the named release with revision") 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") f.BoolVarP(&client.AllValues, "all", "a", false, "dump all (computed) values")
bindOutputFlag(cmd, &outfmt) bindOutputFlag(cmd, &outfmt)

@ -19,6 +19,7 @@ package main
import ( import (
"fmt" "fmt"
"io" "io"
"strconv"
"time" "time"
"github.com/gosuri/uitable" "github.com/gosuri/uitable"
@ -185,3 +186,16 @@ func min(x, y int) int {
} }
return y 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 := cmd.PersistentFlags()
f.IntVar(&client.Version, "revision", 0, "if set, display the status of the named release with revision") 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) bindOutputFlag(cmd, &outfmt)
return cmd return cmd

Loading…
Cancel
Save