feat(comp): Add descriptions for release name comp

Ref: HIP 0008

When completing a release name, extra information will be shown for
shells that support completions (fish, zsh).  For example, if I have
two releases: "nginx" and "nginx2", completion would yield:

$ helm history n<TAB>
nginx   -- nginx-6.0.2 -> deployed
nginx2  -- nginx-ingress-1.41.2 -> deployed

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
pull/9243/head
Marc Khouzam 5 years ago
parent 1f68f658a5
commit a6b28348df

@ -29,9 +29,14 @@ import (
func checkFileCompletion(t *testing.T, cmdName string, shouldBePerformed bool) { func checkFileCompletion(t *testing.T, cmdName string, shouldBePerformed bool) {
storage := storageFixture() storage := storageFixture()
storage.Create(&release.Release{ storage.Create(&release.Release{
Name: "myrelease", Name: "myrelease",
Info: &release.Info{Status: release.StatusDeployed}, Info: &release.Info{Status: release.StatusDeployed},
Chart: &chart.Chart{}, Chart: &chart.Chart{
Metadata: &chart.Metadata{
Name: "Myrelease-Chart",
Version: "1.2.3",
},
},
Version: 1, Version: 1,
}) })

@ -203,14 +203,15 @@ func compListReleases(toComplete string, cfg *action.Configuration) ([]string, c
client.Filter = fmt.Sprintf("^%s", toComplete) client.Filter = fmt.Sprintf("^%s", toComplete)
client.SetStateMask() client.SetStateMask()
results, err := client.Run() releases, err := client.Run()
if err != nil { if err != nil {
return nil, cobra.ShellCompDirectiveDefault return nil, cobra.ShellCompDirectiveDefault
} }
var choices []string var choices []string
for _, res := range results { for _, rel := range releases {
choices = append(choices, res.Name) choices = append(choices,
fmt.Sprintf("%s\t%s-%s -> %s", rel.Name, rel.Chart.Metadata.Name, rel.Chart.Metadata.Version, rel.Info.Status.String()))
} }
return choices, cobra.ShellCompDirectiveNoFileComp return choices, cobra.ShellCompDirectiveNoFileComp

@ -118,56 +118,72 @@ func mustParseTime(t string) helmtime.Time {
} }
func TestStatusCompletion(t *testing.T) { func TestStatusCompletion(t *testing.T) {
releasesMockWithStatus := func(info *release.Info, hooks ...*release.Hook) []*release.Release { rels := []*release.Release{
info.LastDeployed = helmtime.Unix(1452902400, 0).UTC() {
return []*release.Release{{
Name: "athos", Name: "athos",
Namespace: "default", Namespace: "default",
Info: info, Info: &release.Info{
Chart: &chart.Chart{}, Status: release.StatusDeployed,
Hooks: hooks, },
Chart: &chart.Chart{
Metadata: &chart.Metadata{
Name: "Athos-chart",
Version: "1.2.3",
},
},
}, { }, {
Name: "porthos", Name: "porthos",
Namespace: "default", Namespace: "default",
Info: info, Info: &release.Info{
Chart: &chart.Chart{}, Status: release.StatusFailed,
Hooks: hooks, },
Chart: &chart.Chart{
Metadata: &chart.Metadata{
Name: "Porthos-chart",
Version: "111.222.333",
},
},
}, { }, {
Name: "aramis", Name: "aramis",
Namespace: "default", Namespace: "default",
Info: info, Info: &release.Info{
Chart: &chart.Chart{}, Status: release.StatusUninstalled,
Hooks: hooks, },
Chart: &chart.Chart{
Metadata: &chart.Metadata{
Name: "Aramis-chart",
Version: "0.0.0",
},
},
}, { }, {
Name: "dartagnan", Name: "dartagnan",
Namespace: "gascony", Namespace: "gascony",
Info: info, Info: &release.Info{
Chart: &chart.Chart{}, Status: release.StatusUnknown,
Hooks: hooks, },
Chart: &chart.Chart{
Metadata: &chart.Metadata{
Name: "Dartagnan-chart",
Version: "1.2.3-prerelease",
},
},
}} }}
}
tests := []cmdTestCase{{ tests := []cmdTestCase{{
name: "completion for status", name: "completion for status",
cmd: "__complete status a", cmd: "__complete status a",
golden: "output/status-comp.txt", golden: "output/status-comp.txt",
rels: releasesMockWithStatus(&release.Info{ rels: rels,
Status: release.StatusDeployed,
}),
}, { }, {
name: "completion for status with too many arguments", name: "completion for status with too many arguments",
cmd: "__complete status dartagnan ''", cmd: "__complete status dartagnan ''",
golden: "output/status-wrong-args-comp.txt", golden: "output/status-wrong-args-comp.txt",
rels: releasesMockWithStatus(&release.Info{ rels: rels,
Status: release.StatusDeployed,
}),
}, { }, {
name: "completion for status with too many arguments", name: "completion for status with global flag",
cmd: "__complete status --debug a", cmd: "__complete status --debug a",
golden: "output/status-comp.txt", golden: "output/status-comp.txt",
rels: releasesMockWithStatus(&release.Info{ rels: rels,
Status: release.StatusDeployed,
}),
}} }}
runTestCmd(t, tests) runTestCmd(t, tests)
} }

@ -1,4 +1,4 @@
carabins carabins foo-0.1.0-beta.1 -> superseded
musketeers musketeers foo-0.1.0-beta.1 -> deployed
:4 :4
Completion ended with directive: ShellCompDirectiveNoFileComp Completion ended with directive: ShellCompDirectiveNoFileComp

@ -1,4 +1,4 @@
aramis aramis Aramis-chart-0.0.0 -> uninstalled
athos athos Athos-chart-1.2.3 -> deployed
:4 :4
Completion ended with directive: ShellCompDirectiveNoFileComp Completion ended with directive: ShellCompDirectiveNoFileComp

Loading…
Cancel
Save