Skip to content

Commit

Permalink
feat: add CLI flag to specify which occurrence to return
Browse files Browse the repository at this point in the history
  • Loading branch information
shivjm committed Nov 7, 2021
1 parent 32264f5 commit f1fe02c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions main.go
Expand Up @@ -19,6 +19,7 @@ type Image struct {
func main() {
var unknownMarker string
var query string
var occurrence int

var rootCmd = &cobra.Command{
Use: "dockerfile-image-tags",
Expand Down Expand Up @@ -48,7 +49,7 @@ func main() {
if query == "" {
fmt.Println(string(val))
} else {
tag, err := getSingleTag(images, query, 0)
tag, err := getSingleTag(images, query, occurrence)

if err != nil {
log.Fatalf("Could not find image in Dockerfile: %s", query)
Expand All @@ -59,7 +60,8 @@ func main() {
},
}
rootCmd.Flags().StringVarP(&unknownMarker, "unknown-marker", "m", "?", "string to use to indicate unknown tags")
rootCmd.Flags().StringVarP(&query, "query", "q", "", "single image to return tag for (first occurrence)")
rootCmd.Flags().StringVarP(&query, "query", "q", "", "single image to return tag for (see `occurrence`)")
rootCmd.Flags().IntVarP(&occurrence, "occurrence", "n", 1, "which occurrence of the image to return tag for")

if err := rootCmd.Execute(); err != nil {
log.Fatal(err)
Expand Down

0 comments on commit f1fe02c

Please sign in to comment.