Skip to content

Commit

Permalink
Imports all flags from go-quai
Browse files Browse the repository at this point in the history
  • Loading branch information
robschleusner authored and gameofpointers committed Jan 11, 2024
1 parent 63b0649 commit 2063e97
Show file tree
Hide file tree
Showing 5 changed files with 1,052 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ protogen:
## build the go-quai binary
build:
@echo "Building go-quai"
@go build -o go-quai ./cmd/go-quai/main.go
@go build -o go-quai ./cmd/go-quai/main.go
6 changes: 6 additions & 0 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ func init() {
for _, flag := range utils.NodeFlags {
utils.CreateAndBindFlag(flag, startCmd)
}

// Create and bind all rpc flags to the start command
for _, flag := range utils.RPCFlags {
utils.CreateAndBindFlag(flag, startCmd)
}

}

func startCmdPreRun(cmd *cobra.Command, args []string) error {
Expand Down
76 changes: 76 additions & 0 deletions cmd/utils/customflags.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package utils

import (
"encoding"
"fmt"
"math/big"
)

// GenericFlag encapsulates common attributes and an interface for value
type Flag struct {
Name string
Expand All @@ -13,3 +19,73 @@ func (f *Flag) GetName() string { return f.Name }
func (f *Flag) GetAbbreviation() string { return f.Abbreviation }
func (f *Flag) GetUsage() string { return f.Usage }
func (f *Flag) GetValue() interface{} { return f.Value }

// ****************************************
// ** **
// ** BIG INT FLAG **
// ** & CUSTOM VALUE **
// ** **
// ****************************************
type BigIntValue big.Int

func newBigIntValue(val *big.Int) *BigIntValue {
if val == nil {
return nil
}
return (*BigIntValue)(val)
}

func (b *BigIntValue) Set(val string) error {
bigIntVal, ok := new(big.Int).SetString(val, 10)
if !ok {
return fmt.Errorf("failed to parse *big.Int value: %s", val)
}
*b = BigIntValue(*bigIntVal)
return nil
}

func (b *BigIntValue) Type() string {
return "big.Int"
}

func (b *BigIntValue) String() string {
return (*big.Int)(b).String()
}

// ****************************************
// ** **
// ** TEXT MARSHALER FLAG **
// ** & CUSTOM VALUE **
// ** **
// ****************************************
type TextMarshaler interface {
encoding.TextMarshaler
encoding.TextUnmarshaler
}

type TextMarshalerValue struct {
Value encoding.TextMarshaler
}

func NewTextMarshalerValue(val encoding.TextMarshaler) *TextMarshalerValue {
return &TextMarshalerValue{Value: val}
}

func (t *TextMarshalerValue) Set(val string) error {
if unmarshaler, ok := t.Value.(encoding.TextUnmarshaler); ok {
return unmarshaler.UnmarshalText([]byte(val))
}
return fmt.Errorf("value does not implement encoding.TextUnmarshaler")
}

func (t *TextMarshalerValue) Type() string {
return "textMarshaler"
}

func (t *TextMarshalerValue) String() string {
text, err := t.Value.MarshalText()
if err != nil {
return ""
}
return string(text)
}
Loading

0 comments on commit 2063e97

Please sign in to comment.