Skip to content

Commit

Permalink
Merge pull request #2 from stratumfarm/feat-config
Browse files Browse the repository at this point in the history
feat: read config from file or command args
  • Loading branch information
jon4hz authored May 31, 2022
2 parents a2ed2b4 + cf3d09a commit 34765b0
Show file tree
Hide file tree
Showing 4 changed files with 549 additions and 22 deletions.
22 changes: 18 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ import (
mcobra "github.com/muesli/mango-cobra"
"github.com/muesli/roff"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/stratumfarm/derocli/internal/config"
"github.com/stratumfarm/derocli/internal/version"
"github.com/stratumfarm/derocli/pkg/dero"
)

var client *dero.Client
var (
client *dero.Client
cfg *config.Config
)

var rootCmdFlags struct {
rpc string
config string
}

var rootCmd = &cobra.Command{
Expand All @@ -31,7 +36,16 @@ var rootCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(versionCmd, manCmd, allCmd, heightCmd, infoCmd, peersCmd, txPoolCmd)

rootCmd.PersistentFlags().StringVarP(&rootCmdFlags.rpc, "rpc", "r", "localhost:10102", "address of the node")
rootCmd.PersistentFlags().StringVarP(&rootCmdFlags.config, "config", "c", "", "path to the config file")
rootCmd.PersistentFlags().StringP("rpc", "r", "localhost:10102", "address of the node")

viper.BindPFlag("rpc", rootCmd.PersistentFlags().Lookup("rpc"))

var err error
cfg, err = config.Load(rootCmdFlags.config)
if err != nil {
log.Fatalln(err)
}
}

func Execute() error {
Expand All @@ -47,7 +61,7 @@ func prettyPrint(data any) {
}

func connectNode(cmd *cobra.Command, args []string) error {
c, err := dero.New("ws://" + rootCmdFlags.rpc + "/ws")
c, err := dero.New("ws://" + cfg.RPC + "/ws")
if err != nil {
return err
}
Expand Down
24 changes: 18 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,42 @@ require (
github.com/muesli/mango-cobra v1.1.0
github.com/muesli/roff v0.1.0
github.com/spf13/cobra v1.4.0
github.com/spf13/viper v1.12.0
)

require (
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/caarlos0/env/v6 v6.9.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deroproject/graviton v0.0.0-20220130070622-2c248a53b2e1 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/fxamacker/cbor/v2 v2.4.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/klauspost/compress v1.10.3 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/muesli/mango v0.1.0 // indirect
github.com/muesli/mango-pflag v0.1.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/satori/go.uuid v1.2.0 // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.7.0 // indirect
github.com/stretchr/testify v1.7.1 // indirect
github.com/subosito/gotenv v1.3.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0 // indirect
nhooyr.io/websocket v1.8.7 // indirect
)
Loading

0 comments on commit 34765b0

Please sign in to comment.