From c4210399783f2bcfdf3711d5a1d2b2f8aabf8cbb Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Thu, 26 Jun 2014 14:15:21 -0600 Subject: [PATCH] update the init command --- commands/command_init.go | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/commands/command_init.go b/commands/command_init.go index 21ba2f5b..4983e73a 100644 --- a/commands/command_init.go +++ b/commands/command_init.go @@ -2,49 +2,53 @@ package commands import ( "github.com/github/git-media/gitmedia" + "github.com/spf13/cobra" ) -type InitCommand struct { - *Command -} +var ( + initCmd = &cobra.Command{ + Use: "init", + Short: "Initialize the default Git Media configuration.", + Run: initCommand, + } +) -func (c *InitCommand) Run() { +func initCommand(cmd *cobra.Command, args []string) { var sub string - if len(c.SubCommands) > 0 { - sub = c.SubCommands[0] + if len(args) > 0 { + sub = args[0] } switch sub { case "hooks": - c.hookInit() + hookInit() default: - c.runInit() + runInit() } Print("git media initialized") } -func (c *InitCommand) runInit() { - c.globalInit() +func runInit() { + globalInit() + if gitmedia.InRepo() { - c.hookInit() + hookInit() } } -func (c *InitCommand) globalInit() { +func globalInit() { if err := gitmedia.InstallFilters(); err != nil { Error(err.Error()) } } -func (c *InitCommand) hookInit() { +func hookInit() { if err := gitmedia.InstallHooks(); err != nil { Error(err.Error()) } } func init() { - registerCommand("init", func(c *Command) RunnableCommand { - return &InitCommand{Command: c} - }) + RootCmd.AddCommand(initCmd) }