-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(client/v2/autocli): add CoinDec flag #22817
Changes from 5 commits
3077806
59eb5eb
a57b40d
46e7d5c
d7a87db
82f090f
98d1aef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,54 @@ | ||||||||||||||||||||
package flag | ||||||||||||||||||||
|
||||||||||||||||||||
import ( | ||||||||||||||||||||
"context" | ||||||||||||||||||||
"errors" | ||||||||||||||||||||
"strings" | ||||||||||||||||||||
|
||||||||||||||||||||
"google.golang.org/protobuf/reflect/protoreflect" | ||||||||||||||||||||
|
||||||||||||||||||||
basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" | ||||||||||||||||||||
"cosmossdk.io/client/v2/internal/coins" | ||||||||||||||||||||
) | ||||||||||||||||||||
|
||||||||||||||||||||
type decCoinType struct{} | ||||||||||||||||||||
|
||||||||||||||||||||
type decCoinValue struct { | ||||||||||||||||||||
value *basev1beta1.DecCoin | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
func (c decCoinType) NewValue(*context.Context, *Builder) Value { | ||||||||||||||||||||
return &decCoinValue{} | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
func (c decCoinType) DefaultValue() string { | ||||||||||||||||||||
return "zero" | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
func (c *decCoinValue) Get(protoreflect.Value) (protoreflect.Value, error) { | ||||||||||||||||||||
if c.value == nil { | ||||||||||||||||||||
return protoreflect.Value{}, nil | ||||||||||||||||||||
} | ||||||||||||||||||||
return protoreflect.ValueOfMessage(c.value.ProtoReflect()), nil | ||||||||||||||||||||
} | ||||||||||||||||||||
JulianToledano marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||
|
||||||||||||||||||||
func (c *decCoinValue) String() string { | ||||||||||||||||||||
return c.value.String() | ||||||||||||||||||||
} | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add nil check in String method The current implementation could panic if value is nil. Consider adding a nil check: func (c *decCoinValue) String() string {
+ if c.value == nil {
+ return ""
+ }
return c.value.String()
} 📝 Committable suggestion
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @julienrbrt, thank you for addressing the issue! If you found this review helpful, would you consider giving us a shout-out on X? |
||||||||||||||||||||
|
||||||||||||||||||||
func (c *decCoinValue) Set(stringValue string) error { | ||||||||||||||||||||
if strings.Contains(stringValue, ",") { | ||||||||||||||||||||
return errors.New("coin flag must be a single coin, specific multiple coins with multiple flags or spaces") | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
coin, err := coins.ParseDecCoin(stringValue) | ||||||||||||||||||||
if err != nil { | ||||||||||||||||||||
return err | ||||||||||||||||||||
} | ||||||||||||||||||||
c.value = coin | ||||||||||||||||||||
return nil | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
func (c *decCoinValue) Type() string { | ||||||||||||||||||||
return "cosmos.base.v1beta1.DecCoin" | ||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Move changelog entry to Features section
The addition of DecCoin support in autocli flag builder is a new feature rather than a bug fix. Consider moving this entry to the "Features" section:
📝 Committable suggestion