Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianToledano committed Dec 5, 2024
1 parent 9ae0b9f commit c053d1a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
13 changes: 6 additions & 7 deletions client/v2/autocli/prompt/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
// PromptMessage prompts the user for values to populate a protobuf message interactively.
// It returns the populated message and any error encountered during prompting.
func PromptMessage(
addressCodec addresscodec.Codec, validatorAddressCodec addresscodec.Codec,
addressCodec, validatorAddressCodec addresscodec.Codec,
consensusAddressCodec addresscodec.Codec, promptPrefix string, msg protoreflect.Message,
) (protoreflect.Message, error) {
return promptMessage(addressCodec, validatorAddressCodec, consensusAddressCodec, promptPrefix, nil, msg)
Expand All @@ -26,11 +26,10 @@ func PromptMessage(
// promptMessage prompts the user for values to populate a protobuf message interactively.
// stdIn is provided to make the function easier to unit test by allowing injection of predefined inputs.
func promptMessage(
addressCodec addresscodec.Codec, validatorAddressCodec addresscodec.Codec,
addressCodec, validatorAddressCodec addresscodec.Codec,
consensusAddressCodec addresscodec.Codec, promptPrefix string,
stdIn io.ReadCloser, msg protoreflect.Message,
) (protoreflect.Message, error) {

fields := msg.Descriptor().Fields()
for i := 0; i < fields.Len(); i++ {
field := fields.Get(i)
Expand Down Expand Up @@ -178,7 +177,7 @@ func promptList(field protoreflect.FieldDescriptor, msg protoreflect.Message, pr
// promptInnerMessage and promptMessageList respectively.
func promptInnerMessageKind(
f protoreflect.FieldDescriptor, addressCodec addresscodec.Codec,
validatorAddressCodec addresscodec.Codec, consensusAddressCodec addresscodec.Codec,
validatorAddressCodec, consensusAddressCodec addresscodec.Codec,
promptPrefix string, stdIn io.ReadCloser, msg protoreflect.Message,
) error {
if f.IsList() {
Expand All @@ -191,12 +190,12 @@ func promptInnerMessageKind(
// recursively prompts for its fields, and sets the populated message on the parent message.
func promptInnerMessage(
f protoreflect.FieldDescriptor, addressCodec addresscodec.Codec,
validatorAddressCodec addresscodec.Codec, consensusAddressCodec addresscodec.Codec,
validatorAddressCodec, consensusAddressCodec addresscodec.Codec,
promptPrefix string, stdIn io.ReadCloser, msg protoreflect.Message,
) error {
fieldName := promptPrefix + "." + string(f.Name())
nestedMsg := msg.Get(f).Message()
//if nestedMsg.IsValid() {
// if nestedMsg.IsValid() {
// nestedMsg = nestedMsg.New()
//} else {
// nestedMsg = msg.Get(f).Message()
Expand All @@ -223,7 +222,7 @@ func promptInnerMessage(
// prompting for their fields, and appending them to the list until the user chooses to stop.
func promptMessageList(
f protoreflect.FieldDescriptor, addressCodec addresscodec.Codec,
validatorAddressCodec addresscodec.Codec, consensusAddressCodec addresscodec.Codec,
validatorAddressCodec, consensusAddressCodec addresscodec.Codec,
promptPrefix string, stdIn io.ReadCloser, msg protoreflect.Message,
) error {
list := msg.Mutable(f).List()
Expand Down
8 changes: 5 additions & 3 deletions client/v2/autocli/prompt/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"testing"

"github.com/stretchr/testify/require"
"google.golang.org/protobuf/reflect/protoreflect"

"cosmossdk.io/client/v2/internal/testpb"
"google.golang.org/protobuf/reflect/protoreflect"

address2 "github.com/cosmos/cosmos-sdk/codec/address"
)
Expand All @@ -31,11 +31,13 @@ func TestPromptMessage(t *testing.T) {
}{
{
name: "testPb",
inputs: []string{"1", "2", "string", "bytes", "10101010", "0", "234234", "3", "4", "5", "true", "ENUM_ONE",
inputs: []string{
"1", "2", "string", "bytes", "10101010", "0", "234234", "3", "4", "5", "true", "ENUM_ONE",
"bar", "6", "10000", "stake", "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn",
"bytes", "6", "7", "false", "false", "true,false,true", "1,2,3", "hello,hola,ciao", "ENUM_ONE,ENUM_TWO",
"10239", "0", "No", "bar", "343", "No", "134", "positional2", "23455", "stake", "No", "deprecate",
"shorthand", "false", "cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z"},
"shorthand", "false", "cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z",
},
msg: (&testpb.MsgRequest{}).ProtoReflect(),
},
}
Expand Down
3 changes: 3 additions & 0 deletions x/gov/client/cli/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ func NewCmdDraftProposal() *cobra.Command {
}

selectedProposalType, err := prompt.Select("Select proposal type", getProposalSuggestions())
if err != nil {
return fmt.Errorf("failed to prompt proposal types: %w", err)
}
var proposal proposalType
for _, p := range suggestedProposalTypes {
if strings.EqualFold(p.Name, selectedProposalType) {
Expand Down

0 comments on commit c053d1a

Please sign in to comment.