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

fix: version command #135

Merged
merged 8 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,32 @@ package cmd

import (
"fmt"
"runtime/debug"

"github.com/spf13/cobra"
)

// GoBlueprintVersion is the version of the cli to be overwritten by goreleaser in the CI run with the version of the release in github
var GoBlueprintVersion string

func getGoBlueprintVersion() string {
if len(GoBlueprintVersion) != 0 {
return GoBlueprintVersion
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably define this inline and not have a separate variable declared on line 14

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But GoBlueprintVersion needs to be on package level to be able to be set by the ldflag in .goreleaser.yml?
Or am I misunderstanding you?

}
if info, ok := debug.ReadBuildInfo(); ok {
return info.Main.Version
}
return "unknown"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Maybe we can return something else rather than "unknown" since that is a big ambiguous

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, will try to come up with something better

}

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "Display application version information.",
Long: `The version command provides information about the application's version.
Use this command to check the current version of the application.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Go Blueprint CLI version %v\n", GoBlueprintVersion)
version := getGoBlueprintVersion()
fmt.Printf("Go Blueprint CLI version %v\n", version)
},
}
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
- muandane
- SputNikPlop
- Yoquec
- limesten