Skip to content

Commit c6276b3

Browse files
committed
Add version command
1 parent dfd8b3c commit c6276b3

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

.goreleaser.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ builds:
1212
- windows
1313
goarch:
1414
- amd64
15+
ldflags:
16+
- -X "github.com/hashnode/hashnode-cli/cmd.version={{ .Version }}" -X "github.com/hashnode/hashnode-cli/cmd.commithash={{ .FullCommit }}"
17+
1518
archive:
1619
name_template: "hashnode-{{ .Os }}-{{ .Arch }}"
1720
format_overrides:

cmd/version.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
var version, commithash string
10+
11+
// versionCmd represents the version command
12+
var versionCmd = &cobra.Command{
13+
Use: "version",
14+
Short: "Print version number of hashnode",
15+
Run: func(cmd *cobra.Command, args []string) {
16+
fmt.Printf("Release: %s\nCommit: %s\n", version, commithash)
17+
},
18+
}
19+
20+
func init() {
21+
rootCmd.AddCommand(versionCmd)
22+
}

0 commit comments

Comments
 (0)