Skip to content

Commit

Permalink
helm: fix action signature
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Dec 24, 2024
1 parent 5964c9f commit 3e7dc81
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion completers/helm_completer/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func init() {
"version": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if len(c.Args) > 1 {
if splitted := strings.Split(c.Args[1], "/"); len(splitted) == 2 {
return helm.ActionChartVersions(splitted[0], splitted[1])
return helm.ActionChartVersions(helm.ChartVersionOpts{Repo: splitted[0], Chart: splitted[1]})
}
}
return carapace.ActionValues()
Expand Down
2 changes: 1 addition & 1 deletion completers/helm_completer/cmd/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func init() {
"version": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if len(c.Args) > 0 {
if splitted := strings.Split(c.Args[0], "/"); len(splitted) == 2 {
return helm.ActionChartVersions(splitted[0], splitted[1])
return helm.ActionChartVersions(helm.ChartVersionOpts{Repo: splitted[0], Chart: splitted[1]})
}
}
return carapace.ActionValues()
Expand Down
2 changes: 1 addition & 1 deletion completers/helm_completer/cmd/show_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func init() {
"version": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if len(c.Args) > 0 {
if splitted := strings.Split(c.Args[0], "/"); len(splitted) == 2 {
return helm.ActionChartVersions(splitted[0], splitted[1])
return helm.ActionChartVersions(helm.ChartVersionOpts{Repo: splitted[0], Chart: splitted[1]})
}
}
return carapace.ActionValues()
Expand Down
2 changes: 1 addition & 1 deletion completers/helm_completer/cmd/show_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func init() {
"version": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if len(c.Args) > 0 {
if splitted := strings.Split(c.Args[0], "/"); len(splitted) == 2 {
return helm.ActionChartVersions(splitted[0], splitted[1])
return helm.ActionChartVersions(helm.ChartVersionOpts{Repo: splitted[0], Chart: splitted[1]})
}
}
return carapace.ActionValues()
Expand Down
2 changes: 1 addition & 1 deletion completers/helm_completer/cmd/show_readme.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func init() {
"version": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if len(c.Args) > 0 {
if splitted := strings.Split(c.Args[0], "/"); len(splitted) == 2 {
return helm.ActionChartVersions(splitted[0], splitted[1])
return helm.ActionChartVersions(helm.ChartVersionOpts{Repo: splitted[0], Chart: splitted[1]})
}
}
return carapace.ActionValues()
Expand Down
2 changes: 1 addition & 1 deletion completers/helm_completer/cmd/show_values.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func init() {
"version": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if len(c.Args) > 0 {
if splitted := strings.Split(c.Args[0], "/"); len(splitted) == 2 {
return helm.ActionChartVersions(splitted[0], splitted[1])
return helm.ActionChartVersions(helm.ChartVersionOpts{Repo: splitted[0], Chart: splitted[1]})
}
}
return carapace.ActionValues()
Expand Down
2 changes: 1 addition & 1 deletion completers/helm_completer/cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func init() {
"version": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if len(c.Args) > 1 {
if splitted := strings.Split(c.Args[1], "/"); len(splitted) == 2 {
return helm.ActionChartVersions(splitted[0], splitted[1])
return helm.ActionChartVersions(helm.ChartVersionOpts{Repo: splitted[0], Chart: splitted[1]})
}
}
return carapace.ActionValues()
Expand Down
11 changes: 8 additions & 3 deletions pkg/actions/tools/helm/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,23 @@ func ActionCharts(repo string) carapace.Action {
})
}

type ChartVersionOpts struct {
Repo string
Chart string
}

// ActionChartVersions completes chart versions
func ActionChartVersions(repo string, chart string) carapace.Action {
func ActionChartVersions(opts ChartVersionOpts) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
index, err := loadIndex(repo)
index, err := loadIndex(opts.Repo)
if err != nil {
return carapace.ActionMessage(err.Error())
}

vals := make([]string, 0)
for _, charts := range index.Entries {
for _, c := range charts {
if c.Name == chart {
if c.Name == opts.Chart {
vals = append(vals, c.Version)
}
}
Expand Down

0 comments on commit 3e7dc81

Please sign in to comment.