Skip to content

Commit

Permalink
Add example to the cli and add few validations
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilsbhat committed Nov 20, 2022
1 parent 1505bb3 commit a4b468f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ issues:

linters-settings:
funlen:
lines: 100
lines: 160
statements: 60
cyclop:
max-complexity: 30
Expand Down
12 changes: 11 additions & 1 deletion cmd/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"encoding/json"
"errors"
"fmt"
"log"
"os"
"strings"
Expand Down Expand Up @@ -53,7 +54,11 @@ func getImagesCommand() *cobra.Command {
Use: "get [RELEASE] [CHART] [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.",
Args: minimumArgError,
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,
RunE: func(cmd *cobra.Command, args []string) error {
images.SetLogger(images.LogLevel)
images.SetWriter(os.Stdout)
Expand All @@ -64,6 +69,11 @@ func getImagesCommand() *cobra.Command {
images.SetChart(args[1])
}

if (images.JSON && images.YAML && images.Table) || (images.JSON && images.YAML) ||
(images.Table && images.YAML) || (images.Table && images.JSON) {
return fmt.Errorf("cannot render the output to multiple format, enable any of '--yaml --json --table' at a time")
}

return images.GetImages()
},
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ func TestImages_toYAML(t *testing.T) {
}
imagesFiltered := []*k8s.Image{&images}

expected := "---\n- image:\n - prom/pushgateway:v1.3.1\n - jimmidyson/configmap-reload:v0.5.0\n kind: Deployment\n name: sample-deployment\n"
expected := "---\n- image:\n - prom/pushgateway:v1.3.1\n - jimmidyson/configmap-reload:v0.5.0\n " +
"kind: Deployment\n name: sample-deployment\n"
err := imageClient.toYAML(imagesFiltered)
assert.NoError(t, err)
assert.Equal(t, expected, yamlOut.String())
Expand All @@ -49,7 +50,8 @@ func TestImages_toJSON(t *testing.T) {
}
imagesFiltered := []*k8s.Image{&images}

expected := "[\n {\n \"kind\": \"Deployment\",\n \"name\": \"sample-deployment\",\n \"image\": [\n \"prom/pushgateway:v1.3.1\",\n \"jimmidyson/configmap-reload:v0.5.0\"\n ]\n }\n ]"
expected := "[\n {\n \"kind\": \"Deployment\",\n \"name\": \"sample-deployment\",\n " +
"\"image\": [\n \"prom/pushgateway:v1.3.1\",\n \"jimmidyson/configmap-reload:v0.5.0\"\n ]\n }\n ]"
err := imageClient.toJSON(imagesFiltered)
assert.NoError(t, err)
assert.Equal(t, expected, jsonOut.String())
Expand Down

0 comments on commit a4b468f

Please sign in to comment.