Skip to content

Commit

Permalink
fix: parent cmd is null (#120)
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos A Becker <[email protected]>
  • Loading branch information
caarlos0 authored Feb 5, 2023
1 parent 66fb671 commit 453cefb
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 24 deletions.
9 changes: 7 additions & 2 deletions cmd/chglog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ func main() {
return config.ReadInConfig()
}

cmds := commands.AllCommands(config)
cmdRoot.AddCommand(cmds...)
cmdRoot.AddCommand(
commands.AddCmd(config),
commands.InitCmd(config),
commands.VersionCmd(config),
commands.ConfigCmd(config),
commands.FormatCmd(config),
)

if err := cmdRoot.Execute(); err != nil {
// nolint: gomnd, gocritic
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

// nolint: gocognit, funlen, gocritic
func setupAddCmd(config *viper.Viper) (cmd *cobra.Command) {
func AddCmd(config *viper.Viper) (cmd *cobra.Command) {
var (
input,
output,
Expand Down
13 changes: 0 additions & 13 deletions pkg/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,6 @@ import (
"github.com/spf13/viper"
)

// AllCommands returns all commands supported.
func AllCommands(config *viper.Viper) (cmds []*cobra.Command) {
cmds = append(cmds,
setupVersionCmd(config),
setupConfigCmd(config),
setupAddCmd(config),
setupInitCmd(config),
setupFormatCmd(config),
)

return cmds
}

func commonFlags(cmd *cobra.Command, config *viper.Viper) (*cobra.Command, *viper.Viper) {
var (
urgency, owner string
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/spf13/viper"
)

func setupConfigCmd(config *viper.Viper) (cmd *cobra.Command) {
func ConfigCmd(config *viper.Viper) (cmd *cobra.Command) {
var pkg string
cmd = &cobra.Command{
Use: "config",
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
var ErrTemplateFlags = errors.New("--template and --template-file are mutually exclusive")

// nolint: funlen, gocritic
func setupFormatCmd(config *viper.Viper) (cmd *cobra.Command) {
func FormatCmd(config *viper.Viper) (cmd *cobra.Command) {
var input,
output,
pkg,
Expand Down
6 changes: 1 addition & 5 deletions pkg/commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// ErrNoTags happens when a repository has no tags.
var ErrNoTags = errors.New("no versioned releases found, check the output of `git tag`")

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

cmd.PersistentPreRun = func(c *cobra.Command, args []string) {
cmd.Parent().PersistentPreRun(c, args)
}

cmd.RunE = func(c *cobra.Command, args []string) (err error) {
var (
repoPath string
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/spf13/viper"
)

func setupVersionCmd(config *viper.Viper) (cmd *cobra.Command) {
func VersionCmd(config *viper.Viper) (cmd *cobra.Command) {
cmd = &cobra.Command{
Use: "version",
Short: "display version info",
Expand Down

0 comments on commit 453cefb

Please sign in to comment.