Skip to content

Commit

Permalink
feat: refactor configuration handling in stats command
Browse files Browse the repository at this point in the history
- Add `configx` package for configuration handling in stats command
- Initialize configuration using `viper` in stats command
- Add error handling for missing `ton` network in stats command
- Add example configuration file for `ton` network

Signed-off-by: Sean Zheng <[email protected]>
  • Loading branch information
blackhorseya committed Jul 26, 2024
1 parent 5c2119a commit 297fb65
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cmd/get/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,24 @@ package get
import (
"fmt"

"github.com/blackhorseya/ryze/app/infra/configx"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var statsCmd = &cobra.Command{
Use: "stats",
Short: "Get stats",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("stats")
config, err := configx.NewConfiguration(viper.GetViper())
cobra.CheckErr(err)

network, ok := config.Networks["ton"]
if !ok {
cmd.PrintErr("ton network not found")
return
}

fmt.Println(network)
},
}
4 changes: 4 additions & 0 deletions configs/example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
networks:
ton:
name: ton
testnet: false

0 comments on commit 297fb65

Please sign in to comment.