Skip to content

Commit 453cefb

Browse files
authored
fix: parent cmd is null (#120)
Signed-off-by: Carlos A Becker <[email protected]>
1 parent 66fb671 commit 453cefb

File tree

7 files changed

+12
-24
lines changed

7 files changed

+12
-24
lines changed

cmd/chglog/main.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@ func main() {
4545
return config.ReadInConfig()
4646
}
4747

48-
cmds := commands.AllCommands(config)
49-
cmdRoot.AddCommand(cmds...)
48+
cmdRoot.AddCommand(
49+
commands.AddCmd(config),
50+
commands.InitCmd(config),
51+
commands.VersionCmd(config),
52+
commands.ConfigCmd(config),
53+
commands.FormatCmd(config),
54+
)
5055

5156
if err := cmdRoot.Execute(); err != nil {
5257
// nolint: gomnd, gocritic

pkg/commands/add.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
// nolint: gocognit, funlen, gocritic
18-
func setupAddCmd(config *viper.Viper) (cmd *cobra.Command) {
18+
func AddCmd(config *viper.Viper) (cmd *cobra.Command) {
1919
var (
2020
input,
2121
output,

pkg/commands/commands.go

-13
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,6 @@ import (
77
"github.com/spf13/viper"
88
)
99

10-
// AllCommands returns all commands supported.
11-
func AllCommands(config *viper.Viper) (cmds []*cobra.Command) {
12-
cmds = append(cmds,
13-
setupVersionCmd(config),
14-
setupConfigCmd(config),
15-
setupAddCmd(config),
16-
setupInitCmd(config),
17-
setupFormatCmd(config),
18-
)
19-
20-
return cmds
21-
}
22-
2310
func commonFlags(cmd *cobra.Command, config *viper.Viper) (*cobra.Command, *viper.Viper) {
2411
var (
2512
urgency, owner string

pkg/commands/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"github.com/spf13/viper"
66
)
77

8-
func setupConfigCmd(config *viper.Viper) (cmd *cobra.Command) {
8+
func ConfigCmd(config *viper.Viper) (cmd *cobra.Command) {
99
var pkg string
1010
cmd = &cobra.Command{
1111
Use: "config",

pkg/commands/format.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
var ErrTemplateFlags = errors.New("--template and --template-file are mutually exclusive")
1717

1818
// nolint: funlen, gocritic
19-
func setupFormatCmd(config *viper.Viper) (cmd *cobra.Command) {
19+
func FormatCmd(config *viper.Viper) (cmd *cobra.Command) {
2020
var input,
2121
output,
2222
pkg,

pkg/commands/init.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
// ErrNoTags happens when a repository has no tags.
1616
var ErrNoTags = errors.New("no versioned releases found, check the output of `git tag`")
1717

18-
func setupInitCmd(config *viper.Viper) (cmd *cobra.Command) {
18+
func InitCmd(config *viper.Viper) (cmd *cobra.Command) {
1919
var output string
2020
cmd = &cobra.Command{
2121
Use: "init [PATH]",
@@ -31,10 +31,6 @@ func setupInitCmd(config *viper.Viper) (cmd *cobra.Command) {
3131
"changelog.yml",
3232
"file to save the new changelog to")
3333

34-
cmd.PersistentPreRun = func(c *cobra.Command, args []string) {
35-
cmd.Parent().PersistentPreRun(c, args)
36-
}
37-
3834
cmd.RunE = func(c *cobra.Command, args []string) (err error) {
3935
var (
4036
repoPath string

pkg/commands/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/spf13/viper"
88
)
99

10-
func setupVersionCmd(config *viper.Viper) (cmd *cobra.Command) {
10+
func VersionCmd(config *viper.Viper) (cmd *cobra.Command) {
1111
cmd = &cobra.Command{
1212
Use: "version",
1313
Short: "display version info",

0 commit comments

Comments
 (0)