Skip to content

Commit

Permalink
feat: add version command
Browse files Browse the repository at this point in the history
  • Loading branch information
shivjm committed Nov 8, 2021
1 parent 0dbeb60 commit 5b0f84b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cmd/root.go
Expand Up @@ -4,11 +4,15 @@ import (
"github.com/spf13/cobra"
)

const (
ProgramName = "dockerfile-image-tags"
)

var (
unknownMarker string

rootCmd = &cobra.Command{
Use: "dockerfile-image-tags",
Use: ProgramName,
Short: "List or query images and tags used in a Dockerfile.",
}
)
Expand Down
34 changes: 34 additions & 0 deletions cmd/version.go
@@ -0,0 +1,34 @@
package cmd

import (
"fmt"
"strings"

"github.com/spf13/cobra"
)

var Version = "development"
var Revision = ""

var (
versionCmd = &cobra.Command{
Use: "version",
Short: "Prints version",
Long: "Prints the program’s version information.",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
git := ""
r := strings.TrimSpace(Revision)

if len(r) > 0 {
git = fmt.Sprintf(" (r%s)", r)
}

fmt.Printf("%s %s%s", ProgramName, Version, git)
},
}
)

func init() {
rootCmd.AddCommand(versionCmd)
}

0 comments on commit 5b0f84b

Please sign in to comment.