diff --git a/cmd/root.go b/cmd/root.go index 2a06418..47b6e59 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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.", } ) diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..3cbc868 --- /dev/null +++ b/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) +}