Skip to content

Commit

Permalink
feat(root): add version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
iyear committed Jun 29, 2022
1 parent e7f02f2 commit f9e456b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
18 changes: 14 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
package cmd

import (
"github.com/fatih/color"
"github.com/iyear/searchx/cmd/run"
"github.com/iyear/searchx/global"
"github.com/spf13/cobra"
)

var version bool

// TODO
var cmd = &cobra.Command{
Use: "searchx",
Short: "Hugo is a very fast static site generator",
Long: `A Fast and Flexible Static Site Generator built with
love by spf13 and friends in Go.
Complete documentation is available at https://gohugo.io/documentation/`,
Short: "",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
if version {
color.Blue("%s\n%s", global.Version, global.GetRuntime())
}
},
}

func init() {
cmd.AddCommand(run.Cmd)

cmd.PersistentFlags().BoolVarP(&version, "version", "v", false, "check the version of pure-live")

}

func Execute() {
Expand Down
9 changes: 9 additions & 0 deletions global/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
package global

import (
"fmt"
"runtime"
)

var Version string

func GetRuntime() string {
return fmt.Sprintf("%s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH)
}

0 comments on commit f9e456b

Please sign in to comment.