Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/generated-default-config #31

Merged
merged 1 commit into from
Nov 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
)
}