diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 9895c1f..004870d 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -16,6 +16,8 @@ builds: - linux goarch: - amd64 + ldflags: + - -s -w -X github.com/uitml/frink/cmd.version={{ .Version }} -X github.com/uitml/frink/cmd.commit={{ .ShortCommit }} -X github.com/uitml/frink/cmd.date={{ .Date }} archives: - format: binary diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..78ab61c --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,24 @@ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +var ( + version string + commit string + date string +) + +var versionCmd = &cobra.Command{ + Use: "version", + Run: func(cmd *cobra.Command, args []string) { + fmt.Printf("frink v%s\n", version) + }, +} + +func init() { + rootCmd.AddCommand(versionCmd) +} diff --git a/main.go b/main.go index 2ef5e21..5b6c045 100644 --- a/main.go +++ b/main.go @@ -4,12 +4,6 @@ import ( "github.com/uitml/frink/cmd" ) -var ( - version string - commit string - date string -) - func main() { cmd.Execute() }