diff --git a/cmd/root.go b/cmd/root.go index 074f352..1e79ba9 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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() { diff --git a/global/version.go b/global/version.go index 57e884f..40e3fe1 100644 --- a/global/version.go +++ b/global/version.go @@ -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) +}