Skip to content

Commit

Permalink
feat: Only accept single arg for chart or release
Browse files Browse the repository at this point in the history
Release name was unused when referencing a chart.
  • Loading branch information
jimmidyson committed Jun 26, 2023
1 parent 0246a8a commit 99e95de
Showing 1 changed file with 6 additions and 32 deletions.
38 changes: 6 additions & 32 deletions cmd/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"bufio"
"encoding/json"
"errors"
"fmt"
"log"
"os"
Expand All @@ -17,11 +16,6 @@ import (

var images = pkg.Images{}

const (
getArgumentCountLocal = 2
getArgumentCountRelease = 1
)

type imagesCommands struct {
commands []*cobra.Command
}
Expand Down Expand Up @@ -53,22 +47,23 @@ func (c *imagesCommands) prepareCommands() *cobra.Command {

func getImagesCommand() *cobra.Command {
imageCommand := &cobra.Command{
Use: "get [RELEASE] [CHART] [flags]",
Use: "get CHART|RELEASE [flags]",
Short: "Fetches all images those are part of specified chart/release",
Long: "Lists all images those are part of specified chart/release and matches the pattern or part of specified registry.",
Example: ` helm images get prometheus-standalone path/to/chart/prometheus-standalone -f ~/path/to/override-config.yaml
helm images get prometheus-standalone --from-release --registry quay.io
helm images get prometheus-standalone --from-release --registry quay.io --unique
helm images get prometheus-standalone --from-release --registry quay.io --yaml`,
Args: minimumArgError,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
images.SetLogger(images.LogLevel)
images.SetWriter(os.Stdout)
cmd.SilenceUsage = true

images.SetRelease(args[0])
if !images.FromRelease {
images.SetChart(args[1])
if images.FromRelease {
images.SetRelease(args[0])
} else {
images.SetChart(args[0])
}

if (images.JSON && images.YAML && images.Table) || (images.JSON && images.YAML) ||
Expand Down Expand Up @@ -139,27 +134,6 @@ func versionConfig(cmd *cobra.Command, args []string) error {
}

//nolint:goerr113
func minimumArgError(cmd *cobra.Command, args []string) error {
minArgError := errors.New("[RELEASE] or [CHART] cannot be empty")
oneOfThemError := errors.New("when '--from-release' is enabled, valid input is [RELEASE] and not both [RELEASE] [CHART]")
cmd.SilenceUsage = true

if !images.FromRelease {
if len(args) != getArgumentCountLocal {
log.Println(minArgError)

return minArgError
}

return nil
}

if len(args) > getArgumentCountRelease {
log.Fatalln(oneOfThemError)
}

return nil
}

func getUsageTemplate() string {
return `Usage:{{if .Runnable}}
Expand Down

0 comments on commit 99e95de

Please sign in to comment.