Skip to content

Commit

Permalink
feat: add version command
Browse files Browse the repository at this point in the history
  • Loading branch information
ayuhito committed Feb 17, 2023
1 parent 74abb9c commit d30a51d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
8 changes: 5 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ var (
method string
// TODO: headers map[string]string

opts = model.PostMeasurement{}
ctx = model.Context{}
opts = model.PostMeasurement{}
ctx = model.Context{}
version string
)

// rootCmd represents the base command when called without any subcommands
Expand All @@ -40,7 +41,8 @@ var rootCmd = &cobra.Command{

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
func Execute(ver string) {
version = ver
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
Expand Down
19 changes: 19 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

func init() {
rootCmd.AddCommand(versionCmd)
}

var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of Globalping CLI",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Globalping CLI " + version)
},
}
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ package main

import "github.com/jsdelivr/globalping-cli/cmd"

var (
// https://goreleaser.com/cookbooks/using-main.version/
version = "dev"
)

func main() {
cmd.Execute()
cmd.Execute(version)
}

0 comments on commit d30a51d

Please sign in to comment.