Skip to content

Commit 07e2316

Browse files
refactor: remove version callback, pass params
1 parent c449c14 commit 07e2316

File tree

3 files changed

+9
-17
lines changed

3 files changed

+9
-17
lines changed

cmd/callback.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ const (
1919
HookDir = ".commitlint/hooks"
2020
)
2121

22-
// VersionCallback is the version command callback
23-
var VersionCallback = func() error {
24-
fmt.Println("commitlint")
25-
return nil
26-
}
27-
2822
func initCallback(ctx *cli.Context) (retErr error) {
2923
// get user home dir
3024
homeDir, err := os.UserHomeDir()

cmd/cmd.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22
package cmd
33

44
import (
5+
"fmt"
6+
57
"github.com/urfave/cli/v2"
68
)
79

10+
var verTmpl = `commitlint version %s - built from %s on %s
11+
`
12+
813
// New returns commitlint cli.App
9-
func New() *cli.App {
14+
func New(versionNo, commitHash, builtTime string) *cli.App {
1015
createCmd := &cli.Command{
1116
Name: "create",
1217
Usage: "create commitlint config, hooks files",
@@ -69,7 +74,8 @@ func New() *cli.App {
6974
Name: "version",
7075
Usage: "prints commitlint version",
7176
Action: func(c *cli.Context) error {
72-
return VersionCallback()
77+
fmt.Printf(verTmpl, versionNo, commitHash, builtTime)
78+
return nil
7379
},
7480
}
7581

main.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,8 @@ var (
1515
BuildTime = ""
1616
)
1717

18-
var verTmpl = `commitlint %s-%s %s
19-
`
20-
2118
func main() {
22-
cmd.VersionCallback = func() error {
23-
fmt.Printf(verTmpl, Version, Commit, BuildTime)
24-
return nil
25-
}
26-
27-
app := cmd.New()
19+
app := cmd.New(Version, Commit, BuildTime)
2820
err := app.Run(os.Args)
2921
if err != nil {
3022
fmt.Println("Error: ", err)

0 commit comments

Comments
 (0)