Skip to content

Commit

Permalink
Simplify annotation and label flag
Browse files Browse the repository at this point in the history
Simplify the `--annotation` and `--label` flag setup.
  • Loading branch information
HeavyWombat committed Mar 1, 2024
1 parent 32e311f commit 67a0a7e
Showing 1 changed file with 5 additions and 25 deletions.
30 changes: 5 additions & 25 deletions cmd/image-processing/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,14 @@ type settings struct {
help bool
push string
annotation,
label *[]string
label []string
insecure bool
image,
resultFileImageDigest,
resultFileImageSize,
secretPath string
}

func getAnnotation() []string {
var annotation []string

if flagValues.annotation != nil {
return append(annotation, *flagValues.annotation...)
}

return annotation
}

func getLabel() []string {
var label []string

if flagValues.label != nil {
return append(label, *flagValues.label...)
}

return label
}

var flagValues settings

func initializeFlag() {
Expand All @@ -79,8 +59,8 @@ func initializeFlag() {

pflag.StringVar(&flagValues.push, "push", "", "Push the image contained in this directory")

flagValues.annotation = pflag.StringArray("annotation", nil, "New annotations to add")
flagValues.label = pflag.StringArray("label", nil, "New labels to add")
pflag.StringArrayVar(&flagValues.annotation, "annotation", nil, "New annotations to add")
pflag.StringArrayVar(&flagValues.label, "label", nil, "New labels to add")
pflag.StringVar(&flagValues.resultFileImageDigest, "result-file-image-digest", "", "A file to write the image digest to")
pflag.StringVar(&flagValues.resultFileImageSize, "result-file-image-size", "", "A file to write the image size to")
}
Expand Down Expand Up @@ -123,13 +103,13 @@ func runImageProcessing(ctx context.Context) error {
}

// parse annotations
annotations, err := splitKeyVals(getAnnotation())
annotations, err := splitKeyVals(flagValues.annotation)
if err != nil {
return err
}

// parse labels
labels, err := splitKeyVals(getLabel())
labels, err := splitKeyVals(flagValues.label)
if err != nil {
return err
}
Expand Down

0 comments on commit 67a0a7e

Please sign in to comment.