Skip to content

Commit efec50f

Browse files
committed
cmd: create standalone Init function
This will allow us to call this from within a test Signed-off-by: William Casarin <jb55@jb55.com>
1 parent 68a1fee commit efec50f

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

cmd/commit0.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"fmt"
55
"github.com/commitdev/commit0/templator"
6+
"github.com/gobuffalo/packr/v2"
67
"github.com/spf13/cobra"
78
"os"
89
)
@@ -17,8 +18,13 @@ var rootCmd = &cobra.Command{
1718
},
1819
}
1920

20-
func Execute(templates *templator.Templator) {
21-
Templator = templates
21+
func Init() {
22+
templates := packr.New("templates", "../templates")
23+
Templator = templator.NewTemplator(templates)
24+
}
25+
26+
func Execute() {
27+
Init()
2228
if err := rootCmd.Execute(); err != nil {
2329
fmt.Println(err)
2430
os.Exit(1)

main.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@ package main
22

33
import (
44
"github.com/commitdev/commit0/cmd"
5-
"github.com/commitdev/commit0/templator"
6-
"github.com/gobuffalo/packr/v2"
75
)
86

97
func main() {
10-
templates := packr.New("templates", "./templates")
11-
templator := templator.NewTemplator(templates)
12-
cmd.Execute(templator)
8+
cmd.Execute()
139
}

0 commit comments

Comments
 (0)