Skip to content

Commit

Permalink
feat: add version to application config
Browse files Browse the repository at this point in the history
  • Loading branch information
bw-bmbarga committed Aug 31, 2021
1 parent a5cd434 commit 327ee48
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
5 changes: 0 additions & 5 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
builds:
-
ldflags:
- -s -w -X cmd.version={{.Version}} -X cmd.commit={{.Commit}} -X cmd.date={{.Date}} -X cmd.builtBy=elhmn

brews:
- tap:
owner: elhmn
Expand Down
2 changes: 1 addition & 1 deletion cmd/add_code_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func createConfig(t *testing.T) config.Config {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

conf := config.NewDefaultConfig()
conf := config.NewDefaultConfig(config.Options{Version: "0.0.0.dev"})
conf.Exec = mocks.NewMockIExec(mockCtrl)
conf.Printers = mocks.NewMockIPrinters(mockCtrl)

Expand Down
3 changes: 1 addition & 2 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
)

//This version will be set by a goreleaser ldflag
var version = "0.0.0.dev"
var versionString = `Version: %s
Build by elhmn
Support osscameroon here https://opencollective.com/osscameroon
Expand All @@ -31,6 +30,6 @@ func NewVersionCommand(conf config.Config) *cobra.Command {
}

func versionCommand(conf config.Config) error {
fmt.Fprintf(conf.OutWriter, versionString, version)
fmt.Fprintf(conf.OutWriter, versionString, conf.Version)
return nil
}
9 changes: 8 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (

//Config contains the entire cli dependencies
type Config struct {
Version string
Viper viper.Viper
Exec exec.IExec
CKPDir string
Expand All @@ -43,8 +44,13 @@ type Config struct {
ErrWriter io.Writer
}

//Options config options
type Options struct {
Version string
}

//NewDefaultConfig creates a new default config
func NewDefaultConfig() Config {
func NewDefaultConfig(opt Options) Config {
conf := Config{
Exec: exec.NewExec(),
Spin: printers.NewSpinner(),
Expand All @@ -55,6 +61,7 @@ func NewDefaultConfig() Config {
CKPStorageFolder: "repo",
MainBranch: MainBranch,
WorkingBranch: "working-" + MainBranch,
Version: opt.Version,
}

conf.Viper = setupViper(conf)
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"github.com/elhmn/ckp/internal/config"
)

var version = "0.0.0.dev"

func main() {
conf := config.NewDefaultConfig()
conf := config.NewDefaultConfig(config.Options{Version: version})
command := cmd.NewCKPCommand(conf)

err := command.Execute()
Expand Down

0 comments on commit 327ee48

Please sign in to comment.