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

feat: Use version from Goreleaser #148

Merged
merged 2 commits into from
Jul 17, 2024
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
16 changes: 13 additions & 3 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package cmd

import (
"github.com/oslokommune/ok/internal/scriptrunner"
_ "embed"
"fmt"
"github.com/spf13/cobra"
)

var VersionData Version

func init() {
rootCmd.AddCommand(versionCmd)
}
Expand All @@ -13,7 +16,14 @@ var versionCmd = &cobra.Command{
Use: "version",
Short: "Prints the version of the ok tool and the current latest version available.",
Run: func(cmd *cobra.Command, args []string) {
fullArgs := append([]string{"version"}, args...)
scriptrunner.RunScript("ok.sh", fullArgs)
fmt.Printf("Version: %s\n", VersionData.Version)
fmt.Printf("Date: %s\n", VersionData.Date)
fmt.Printf("Commit: %s\n", VersionData.Commit)
},
}

type Version struct {
Version string
Date string
Commit string
}
13 changes: 13 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,21 @@ import (
"os"
)

var (
version = "dev"
date = "unknown"
commit = "none"
)

func main() {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout})

cmd.VersionData = cmd.Version{
Version: version,
Date: date,
Commit: commit,
}

cmd.Execute()

}