Skip to content
This repository was archived by the owner on Sep 14, 2022. It is now read-only.

Commit 76b68df

Browse files
committed
pvcexec-4 Implement version sub-command
1 parent da7d4d2 commit 76b68df

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

.goreleaser.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
builds:
2-
- main: main.go
2+
-
3+
main: main.go
34
binary: kubectl-pvcexec
5+
# Custom ldflags templates.
6+
# Default is `-s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}}`.
7+
ldflags:
8+
- --s -w -X github.com/kubextender/pvcexec/pkg/cmd.version={{.Version}} -X github.com/kubextender/pvcexec/pkg/cmd.commit={{.ShortCommit}} -X github.com/kubextender/pvcexec/pkg/cmd.date={{.Date}}
49
goos:
510
- darwin
611
- linux

pkg/cmd/pvcexec.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ func NewPvcExecCmd(streams genericclioptions.IOStreams) *cobra.Command {
2929
o := NewPvcExecOptions(streams)
3030
cmd.AddCommand(NewMcCommand(o))
3131
cmd.AddCommand(NewZshCommand(o))
32+
cmd.AddCommand(NewVersionCommand(streams))
3233
return cmd
3334
}

pkg/cmd/version.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"github.com/spf13/cobra"
6+
"k8s.io/cli-runtime/pkg/genericclioptions"
7+
)
8+
9+
var (
10+
version = "dev"
11+
commit = "none"
12+
date = "unknown"
13+
)
14+
15+
func GetVersion() string {
16+
return fmt.Sprintf("Version=%v (commit %v, built at %v)", version, commit, date)
17+
}
18+
19+
// NewVersionCommand provides the version command.
20+
func NewVersionCommand(streams genericclioptions.IOStreams) *cobra.Command {
21+
cmd := &cobra.Command{
22+
Use: "version",
23+
Short: "Print the version information for pvcexec",
24+
RunE: func(c *cobra.Command, args []string) error {
25+
fmt.Fprintln(streams.Out, GetVersion())
26+
return nil
27+
},
28+
}
29+
return cmd
30+
}

0 commit comments

Comments
 (0)