Skip to content

Commit

Permalink
chore: Change versioning params to optional using cobrax library
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Nov 15, 2024
1 parent 4698f0d commit e774400
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 22 deletions.
5 changes: 1 addition & 4 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ builds:
ldflags:
- -s
- -w
- -X main.version=v{{.Version}}
- -X main.commit={{.ShortCommit}}
- -X main.date={{.CommitDate}}
- -X main.builtBy=goreleaser
- -X main.version={{.Version}}
goarch:
- amd64
- arm64
Expand Down
13 changes: 8 additions & 5 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@ import (

"gabe565.com/changelog-generator/internal/config"
"gabe565.com/changelog-generator/internal/git"
"gabe565.com/utils/cobrax"
"github.com/spf13/cobra"
)

func New(version, commit string) *cobra.Command {
func New(opts ...cobrax.Option) *cobra.Command {
cmd := &cobra.Command{
Use: "changelog-generator",
Short: "Generates a changelog from commits since the previous release",
RunE: run,
Version: buildVersion(version, commit),
Use: "changelog-generator",
Short: "Generates a changelog from commits since the previous release",
RunE: run,

Args: cobra.NoArgs,
ValidArgsFunction: cobra.NoFileCompletions,
DisableAutoGenTag: true,
}
config.RegisterFlags(cmd)
for _, opt := range opts {
opt(cmd)
}
return cmd
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type stubCmd struct {
func newStubCmd(t *testing.T) *stubCmd {
temp, err := os.MkdirTemp("", "changelog-generator-")
require.NoError(t, err)
cmd := &stubCmd{Command: New("", ""), tempPath: temp}
cmd := &stubCmd{Command: New(), tempPath: temp}
require.NoError(t, cmd.Flags().Set(config.RepoFlag, cmd.tempPath))
cmd.SetArgs([]string{})
return cmd
Expand Down
1 change: 1 addition & 0 deletions docs/changelog-generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ changelog-generator [flags]
--config string Config file (default ".changelog-generator.yaml")
-h, --help help for changelog-generator
--repo string Path to the git repo root. Parent directories will be walked until .git is found. (default ".")
-v, --version version for changelog-generator
```

3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module gabe565.com/changelog-generator
go 1.23.3

require (
gabe565.com/utils v0.0.0-20241114234101-e128cd3269b5
github.com/go-git/go-git/v5 v5.12.0
github.com/knadh/koanf/parsers/yaml v0.1.0
github.com/knadh/koanf/providers/confmap v0.1.0
Expand Down Expand Up @@ -44,7 +45,7 @@ require (
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/tools v0.19.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
gabe565.com/utils v0.0.0-20241114234101-e128cd3269b5 h1:uqtftvk1FMAsFPAT9ICLLntGsZHmrghgIGBClVCsVHk=
gabe565.com/utils v0.0.0-20241114234101-e128cd3269b5/go.mod h1:1WioSVukwGZYG4Q0LJBnRhgYyVljmW2Izl+RW36ALUc=
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
Expand Down Expand Up @@ -140,8 +142,8 @@ golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
Expand Down
2 changes: 1 addition & 1 deletion internal/generate/completions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func main() {
panic(err)
}

rootCmd := cmd.New("", "")
rootCmd := cmd.New()
name := rootCmd.Name()
var buf bytes.Buffer
rootCmd.SetOut(&buf)
Expand Down
3 changes: 2 additions & 1 deletion internal/generate/docs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"

"gabe565.com/changelog-generator/cmd"
"gabe565.com/utils/cobrax"
"github.com/spf13/cobra/doc"
)

Expand All @@ -23,7 +24,7 @@ func main() {
log.Fatal(fmt.Errorf("failed to mkdir: %w", err))
}

rootCmd := cmd.New("", "")
rootCmd := cmd.New(cobrax.WithVersion("beta"))

err = doc.GenMarkdownTree(rootCmd, output)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/generate/manpages/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func main() {
panic(err)
}

rootCmd := cmd.New("", "")
rootCmd := cmd.New()
rootName := rootCmd.Name()

date, err := time.Parse(time.RFC3339, dateParam)
Expand Down
10 changes: 4 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ import (
"os"

"gabe565.com/changelog-generator/cmd"
"gabe565.com/utils/cobrax"
)

//nolint:gochecknoglobals
var (
version = "beta"
commit = ""
)
var version = "beta"

func main() {
if err := cmd.New(version, commit).Execute(); err != nil {
root := cmd.New(cobrax.WithVersion(version))
if err := root.Execute(); err != nil {
os.Exit(1)
}
}

0 comments on commit e774400

Please sign in to comment.