Skip to content

Commit

Permalink
cmd: create standalone Init function
Browse files Browse the repository at this point in the history
This will allow us to call this from within a test

Signed-off-by: William Casarin <jb55@jb55.com>
  • Loading branch information
jb55 committed Oct 11, 2019
1 parent 68a1fee commit efec50f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 8 additions & 2 deletions cmd/commit0.go
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"github.com/commitdev/commit0/templator"
"github.com/gobuffalo/packr/v2"
"github.com/spf13/cobra"
"os"
)
Expand All @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions main.go
Expand Up @@ -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()
}

0 comments on commit efec50f

Please sign in to comment.