From 9e95c6ef68d5cb982810a4700fd1e52f70f063c3 Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Thu, 26 Jun 2014 15:14:11 -0600 Subject: [PATCH] root cmd shows help and version --- commands/command_version.go | 9 ++++++++- commands/commands.go | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/commands/command_version.go b/commands/command_version.go index ff227f22..7325f216 100644 --- a/commands/command_version.go +++ b/commands/command_version.go @@ -16,7 +16,14 @@ var ( ) func versionCommand(cmd *cobra.Command, args []string) { - Print("%s v%s", cmd.Parent().Name(), gitmedia.Version) + var parent *cobra.Command + if p := cmd.Parent(); p != nil { + parent = p + } else { + parent = cmd + } + + Print("%s v%s", parent.Name(), gitmedia.Version) if lovesComics { Print("Nothing may see Gah Lak Tus and survive!") diff --git a/commands/commands.go b/commands/commands.go index 8923c917..80b7b490 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -24,7 +24,8 @@ var ( Use: "git-media", Short: "Git Media provides large file support to Git.", Run: func(cmd *cobra.Command, args []string) { - fmt.Println("Git Media, yo") + versionCommand(cmd, args) + cmd.Help() }, } )