Skip to content

Commit

Permalink
Merge pull request #31 from restechnica/feature/generated-default-config
Browse files Browse the repository at this point in the history
feature/generated-default-config
  • Loading branch information
shiouen committed Nov 20, 2021
2 parents f42b302 + f94c962 commit 2d6a15c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 32 deletions.
27 changes: 0 additions & 27 deletions internal/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,6 @@ package internal
import "github.com/restechnica/semverbot/pkg/modes"

const (
// DefaultConfig the default config.
DefaultConfig = `mode = "auto"
[git]
[git.config]
email = "semverbot@github.com"
name = "semverbot"
[git.tags]
prefix = "v"
[semver]
patch = ["fix", "bug"]
minor = ["feature"]
major = ["release"]
[modes]
[modes.git-branch]
delimiters = "/"
[modes.git-commit]
delimiters = "[]"
`

// DefaultConfigFilePath the default relative filepath to the config file.
DefaultConfigFilePath = ".semverbot.toml"

Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NewInitCommand() *cobra.Command {
// Returns an error if the command failed.
func InitCommandRunE(cmd *cobra.Command, args []string) (err error) {
var options = &core.InitOptions{
Config: cli.DefaultConfig,
Config: cli.GetDefaultConfig(),
ConfigFilePath: cli.DefaultConfigFilePath,
}

Expand Down
45 changes: 41 additions & 4 deletions pkg/cli/defaults.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package cli

import "github.com/restechnica/semverbot/internal"
import (
"fmt"

var (
// DefaultConfig the default config.
DefaultConfig = internal.DefaultConfig
"github.com/restechnica/semverbot/internal"
)

var (
// DefaultConfigFilePath the default relative filepath to the config file.
DefaultConfigFilePath = internal.DefaultConfigFilePath

Expand All @@ -24,3 +25,39 @@ var (
// DefaultVersion the default version when no other version can be found.
DefaultVersion = internal.DefaultVersion
)

func GetDefaultConfig() string {
const template = `mode = "%s"
[git]
[git.config]
email = "semverbot@github.com"
name = "semverbot"
[git.tags]
prefix = "%s"
[semver]
patch = ["fix", "bug"]
minor = ["feature"]
major = ["release"]
[modes]
[modes.git-branch]
delimiters = "%s"
[modes.git-commit]
delimiters = "%s"
`

return fmt.Sprintf(
template,
DefaultMode,
DefaultGitTagsPrefix,
DefaultGitBranchDelimiters,
DefaultGitCommitDelimiters,
)
}

0 comments on commit 2d6a15c

Please sign in to comment.