From efec50fc980a0372abde657c5cdeaaf91d378fc6 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Thu, 10 Oct 2019 16:53:41 -0700 Subject: [PATCH] cmd: create standalone Init function This will allow us to call this from within a test Signed-off-by: William Casarin --- cmd/commit0.go | 10 ++++++++-- main.go | 6 +----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/cmd/commit0.go b/cmd/commit0.go index f54cf238b..8d74067ef 100644 --- a/cmd/commit0.go +++ b/cmd/commit0.go @@ -3,6 +3,7 @@ package cmd import ( "fmt" "github.com/commitdev/commit0/templator" + "github.com/gobuffalo/packr/v2" "github.com/spf13/cobra" "os" ) @@ -17,8 +18,13 @@ var rootCmd = &cobra.Command{ }, } -func Execute(templates *templator.Templator) { - Templator = templates +func Init() { + templates := packr.New("templates", "../templates") + Templator = templator.NewTemplator(templates) +} + +func Execute() { + Init() if err := rootCmd.Execute(); err != nil { fmt.Println(err) os.Exit(1) diff --git a/main.go b/main.go index 825c5f7fb..7c249737b 100644 --- a/main.go +++ b/main.go @@ -2,12 +2,8 @@ package main import ( "github.com/commitdev/commit0/cmd" - "github.com/commitdev/commit0/templator" - "github.com/gobuffalo/packr/v2" ) func main() { - templates := packr.New("templates", "./templates") - templator := templator.NewTemplator(templates) - cmd.Execute(templator) + cmd.Execute() }