Skip to content

Commit

Permalink
feat(cnivpctl): add version command (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
fioncat committed Jul 5, 2023
1 parent a2baa08 commit 91ad668
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
10 changes: 1 addition & 9 deletions cmd/cnivpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ import (
"github.com/vishvananda/netlink"
)

func showVersion() {
fmt.Println("CNI Version: \t" + vs.CNIVersion)
fmt.Println("Go Version: \t" + runtime.Version())
fmt.Printf("Go OS/Arch: \t%s/%s\n", runtime.GOOS, runtime.GOARCH)
fmt.Println("Build Time: \t" + vs.BuildTime)
fmt.Println("Git Commit ID: \t" + vs.ProgramCommitID)
}

func init() {
// this ensures that main runs only on main thread (thread group leader).
// since namespace ops (unshare, setns) are done for a single thread, we
Expand Down Expand Up @@ -314,7 +306,7 @@ func tickSuicide(done chan bool) {
func main() {
// Print version
if len(os.Args) == 2 && os.Args[1] == "version" {
showVersion()
vs.Show()
os.Exit(0)
}

Expand Down
13 changes: 13 additions & 0 deletions cmd/cnivpctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"os"

"github.com/spf13/cobra"
"github.com/ucloud/uk8s-cni-vpc/pkg/version"
)

var cmd = &cobra.Command{
Expand All @@ -27,12 +28,24 @@ var cmd = &cobra.Command{
SilenceErrors: true,
SilenceUsage: true,

Version: version.CNIVersion,

CompletionOptions: cobra.CompletionOptions{
HiddenDefaultCmd: true,
},
}

var versionCmd = &cobra.Command{
Use: "version",
Short: "Show cnivpctl version",

Run: func(_ *cobra.Command, _ []string) {
version.Show()
},
}

func main() {
cmd.AddCommand(versionCmd)
cmd.AddCommand(getCmd, releaseCmd, popCmd, pushCmd)

err := cmd.Execute()
Expand Down
13 changes: 13 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,22 @@

package version

import (
"fmt"
"runtime"
)

// Build and version information
var (
BuildTime = ""
ProgramCommitID = ""
CNIVersion = ""
)

func Show() {
fmt.Println("CNI Version: \t" + CNIVersion)
fmt.Println("Go Version: \t" + runtime.Version())
fmt.Printf("Go OS/Arch: \t%s/%s\n", runtime.GOOS, runtime.GOARCH)
fmt.Println("Build Time: \t" + BuildTime)
fmt.Println("Git Commit ID: \t" + ProgramCommitID)
}

0 comments on commit 91ad668

Please sign in to comment.