Skip to content

Commit

Permalink
Merge pull request #12 from konstructio/fly-49-versioncmd
Browse files Browse the repository at this point in the history
initial version command for colony cli
  • Loading branch information
jarededwards authored Oct 31, 2024
2 parents 4097b6b + e909a3c commit 682b165
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ go.work
go.work.sum

# env file
.env
.env
tmp/
dist/
1 change: 1 addition & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ builds:
- -trimpath
ldflags:
- -s -w -extldflags "-static"
- -X github.com/konstructio/colony/configs.Version=v{{.Version}}

archives:
- format: tar.gz
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ func GetRootCommand() *cobra.Command {
SilenceErrors: true, // we print the errors ourselves on main
}

cmd.AddCommand(getInitCommand())
cmd.AddCommand(getInitCommand(), getVersionCommand())
return cmd
}
22 changes: 22 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cmd

import (
"github.com/konstructio/colony/configs"
"github.com/konstructio/colony/internal/logger"
"github.com/spf13/cobra"
)

func getVersionCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "version",
Short: "print the version for colony cli",
Long: `print the version for colony cli`,
RunE: func(cmd *cobra.Command, args []string) error {
log := logger.New(logger.Debug)

log.Info("colony cli version: ", configs.Version)
return nil
},
}
return cmd
}
12 changes: 12 additions & 0 deletions configs/configs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package configs

const (
DefaultVersion = "development"
)

//nolint:gochecknoglobals // used to store the version of the built binary
var Version = DefaultVersion

type Config struct {
Version string
}

0 comments on commit 682b165

Please sign in to comment.