mirror of
https://github.com/alexgo-io/gaze-indexer.git
synced 2026-04-30 04:35:13 +08:00
@@ -51,6 +51,7 @@ func Execute() {
|
||||
|
||||
// Execute command
|
||||
if err := cmd.Execute(); err != nil {
|
||||
logger.Panic("Failed to execute root command", slogx.Error(err))
|
||||
// use cobra to log error message by default
|
||||
logger.Debug("Failed to execute root command", slogx.Error(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,19 +3,47 @@ package cmd
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
"github.com/gaze-network/indexer-network/common/errs"
|
||||
"github.com/gaze-network/indexer-network/core/constants"
|
||||
"github.com/gaze-network/indexer-network/modules/bitcoin"
|
||||
"github.com/gaze-network/indexer-network/modules/runes"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func NewVersionCommand() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Show indexer-network version",
|
||||
RunE: versionHandler,
|
||||
}
|
||||
var versions = map[string]string{
|
||||
"": constants.Version,
|
||||
"bitcoin": bitcoin.Version,
|
||||
"runes": runes.Version,
|
||||
}
|
||||
|
||||
func versionHandler(cmd *cobra.Command, args []string) error {
|
||||
// TODO: create constant package
|
||||
fmt.Println("gaze-network v0.0.1")
|
||||
type versionCmdOptions struct {
|
||||
Modules string
|
||||
}
|
||||
|
||||
func NewVersionCommand() *cobra.Command {
|
||||
opts := &versionCmdOptions{}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Show indexer-network version",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return versionHandler(opts, cmd, args)
|
||||
},
|
||||
}
|
||||
|
||||
flags := cmd.Flags()
|
||||
flags.StringVar(&opts.Modules, "module", "", `Show version of a specific module. E.g. "bitcoin" | "runes"`)
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func versionHandler(opts *versionCmdOptions, _ *cobra.Command, _ []string) error {
|
||||
version, ok := versions[opts.Modules]
|
||||
if !ok {
|
||||
// fmt.Fprintln(cmd.ErrOrStderr(), "Unknown module")
|
||||
return errors.Wrap(errs.Unsupported, "Invalid module name")
|
||||
}
|
||||
fmt.Println(version)
|
||||
return nil
|
||||
}
|
||||
|
||||
5
core/constants/constants.go
Normal file
5
core/constants/constants.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package constants
|
||||
|
||||
const (
|
||||
Version = "v0.0.1"
|
||||
)
|
||||
5
modules/bitcoin/constants.go
Normal file
5
modules/bitcoin/constants.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package bitcoin
|
||||
|
||||
const (
|
||||
Version = "v0.0.1"
|
||||
)
|
||||
5
modules/runes/constants.go
Normal file
5
modules/runes/constants.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package runes
|
||||
|
||||
const (
|
||||
Version = "v0.0.1"
|
||||
)
|
||||
Reference in New Issue
Block a user