diff --git a/api/cosmos/autocli/v1/options.pulsar.go b/api/cosmos/autocli/v1/options.pulsar.go index bee3f403bfce..8d414adb4237 100644 --- a/api/cosmos/autocli/v1/options.pulsar.go +++ b/api/cosmos/autocli/v1/options.pulsar.go @@ -3949,10 +3949,11 @@ func (x *fastReflection_FlagOptions) ProtoMethods() *protoiface.Methods { } var ( - md_PositionalArgDescriptor protoreflect.MessageDescriptor - fd_PositionalArgDescriptor_proto_field protoreflect.FieldDescriptor - fd_PositionalArgDescriptor_varargs protoreflect.FieldDescriptor - fd_PositionalArgDescriptor_optional protoreflect.FieldDescriptor + md_PositionalArgDescriptor protoreflect.MessageDescriptor + fd_PositionalArgDescriptor_proto_field protoreflect.FieldDescriptor + fd_PositionalArgDescriptor_varargs protoreflect.FieldDescriptor + fd_PositionalArgDescriptor_optional protoreflect.FieldDescriptor + fd_PositionalArgDescriptor_flatten_fields protoreflect.FieldDescriptor ) func init() { @@ -3961,6 +3962,7 @@ func init() { fd_PositionalArgDescriptor_proto_field = md_PositionalArgDescriptor.Fields().ByName("proto_field") fd_PositionalArgDescriptor_varargs = md_PositionalArgDescriptor.Fields().ByName("varargs") fd_PositionalArgDescriptor_optional = md_PositionalArgDescriptor.Fields().ByName("optional") + fd_PositionalArgDescriptor_flatten_fields = md_PositionalArgDescriptor.Fields().ByName("flatten_fields") } var _ protoreflect.Message = (*fastReflection_PositionalArgDescriptor)(nil) @@ -4046,6 +4048,12 @@ func (x *fastReflection_PositionalArgDescriptor) Range(f func(protoreflect.Field return } } + if x.FlattenFields != false { + value := protoreflect.ValueOfBool(x.FlattenFields) + if !f(fd_PositionalArgDescriptor_flatten_fields, value) { + return + } + } } // Has reports whether a field is populated. @@ -4067,6 +4075,8 @@ func (x *fastReflection_PositionalArgDescriptor) Has(fd protoreflect.FieldDescri return x.Varargs != false case "cosmos.autocli.v1.PositionalArgDescriptor.optional": return x.Optional != false + case "cosmos.autocli.v1.PositionalArgDescriptor.flatten_fields": + return x.FlattenFields != false default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.autocli.v1.PositionalArgDescriptor")) @@ -4089,6 +4099,8 @@ func (x *fastReflection_PositionalArgDescriptor) Clear(fd protoreflect.FieldDesc x.Varargs = false case "cosmos.autocli.v1.PositionalArgDescriptor.optional": x.Optional = false + case "cosmos.autocli.v1.PositionalArgDescriptor.flatten_fields": + x.FlattenFields = false default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.autocli.v1.PositionalArgDescriptor")) @@ -4114,6 +4126,9 @@ func (x *fastReflection_PositionalArgDescriptor) Get(descriptor protoreflect.Fie case "cosmos.autocli.v1.PositionalArgDescriptor.optional": value := x.Optional return protoreflect.ValueOfBool(value) + case "cosmos.autocli.v1.PositionalArgDescriptor.flatten_fields": + value := x.FlattenFields + return protoreflect.ValueOfBool(value) default: if descriptor.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.autocli.v1.PositionalArgDescriptor")) @@ -4140,6 +4155,8 @@ func (x *fastReflection_PositionalArgDescriptor) Set(fd protoreflect.FieldDescri x.Varargs = value.Bool() case "cosmos.autocli.v1.PositionalArgDescriptor.optional": x.Optional = value.Bool() + case "cosmos.autocli.v1.PositionalArgDescriptor.flatten_fields": + x.FlattenFields = value.Bool() default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.autocli.v1.PositionalArgDescriptor")) @@ -4166,6 +4183,8 @@ func (x *fastReflection_PositionalArgDescriptor) Mutable(fd protoreflect.FieldDe panic(fmt.Errorf("field varargs of message cosmos.autocli.v1.PositionalArgDescriptor is not mutable")) case "cosmos.autocli.v1.PositionalArgDescriptor.optional": panic(fmt.Errorf("field optional of message cosmos.autocli.v1.PositionalArgDescriptor is not mutable")) + case "cosmos.autocli.v1.PositionalArgDescriptor.flatten_fields": + panic(fmt.Errorf("field flatten_fields of message cosmos.autocli.v1.PositionalArgDescriptor is not mutable")) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.autocli.v1.PositionalArgDescriptor")) @@ -4185,6 +4204,8 @@ func (x *fastReflection_PositionalArgDescriptor) NewField(fd protoreflect.FieldD return protoreflect.ValueOfBool(false) case "cosmos.autocli.v1.PositionalArgDescriptor.optional": return protoreflect.ValueOfBool(false) + case "cosmos.autocli.v1.PositionalArgDescriptor.flatten_fields": + return protoreflect.ValueOfBool(false) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.autocli.v1.PositionalArgDescriptor")) @@ -4264,6 +4285,9 @@ func (x *fastReflection_PositionalArgDescriptor) ProtoMethods() *protoiface.Meth if x.Optional { n += 2 } + if x.FlattenFields { + n += 2 + } if x.unknownFields != nil { n += len(x.unknownFields) } @@ -4293,6 +4317,16 @@ func (x *fastReflection_PositionalArgDescriptor) ProtoMethods() *protoiface.Meth i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } + if x.FlattenFields { + i-- + if x.FlattenFields { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x70 + } if x.Optional { i-- if x.Optional { @@ -4441,6 +4475,26 @@ func (x *fastReflection_PositionalArgDescriptor) ProtoMethods() *protoiface.Meth } } x.Optional = bool(v != 0) + case 14: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field FlattenFields", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + x.FlattenFields = bool(v != 0) default: iNdEx = preIndex skippy, err := runtime.Skip(dAtA[iNdEx:]) @@ -4886,6 +4940,8 @@ type PositionalArgDescriptor struct { // optional makes the last positional parameter optional. // Note: It is mutually exclusive with varargs. Optional bool `protobuf:"varint,3,opt,name=optional,proto3" json:"optional,omitempty"` + // TODO: doc + FlattenFields bool `protobuf:"varint,14,opt,name=flatten_fields,json=flattenFields,proto3" json:"flatten_fields,omitempty"` } func (x *PositionalArgDescriptor) Reset() { @@ -4929,6 +4985,13 @@ func (x *PositionalArgDescriptor) GetOptional() bool { return false } +func (x *PositionalArgDescriptor) GetFlattenFields() bool { + if x != nil { + return x.FlattenFields + } + return false +} + var File_cosmos_autocli_v1_options_proto protoreflect.FileDescriptor var file_cosmos_autocli_v1_options_proto_rawDesc = []byte{ @@ -5025,26 +5088,28 @@ var file_cosmos_autocli_v1_options_proto_rawDesc = []byte{ 0x28, 0x09, 0x52, 0x13, 0x73, 0x68, 0x6f, 0x72, 0x74, 0x68, 0x61, 0x6e, 0x64, 0x44, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x69, 0x64, 0x64, 0x65, 0x6e, 0x18, 0x08, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x68, 0x69, 0x64, 0x64, 0x65, 0x6e, 0x22, - 0x70, 0x0a, 0x17, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x41, 0x72, 0x67, - 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x12, 0x1f, 0x0a, 0x0b, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x5f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x0a, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x76, - 0x61, 0x72, 0x61, 0x72, 0x67, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x76, 0x61, - 0x72, 0x61, 0x72, 0x67, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x61, - 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x61, - 0x6c, 0x42, 0xb9, 0x01, 0x0a, 0x15, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, - 0x2e, 0x61, 0x75, 0x74, 0x6f, 0x63, 0x6c, 0x69, 0x2e, 0x76, 0x31, 0x42, 0x0c, 0x4f, 0x70, 0x74, - 0x69, 0x6f, 0x6e, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x2c, 0x63, 0x6f, 0x73, - 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, - 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x61, 0x75, 0x74, 0x6f, 0x63, 0x6c, 0x69, 0x2f, 0x76, 0x31, 0x3b, - 0x61, 0x75, 0x74, 0x6f, 0x63, 0x6c, 0x69, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x41, 0x58, 0xaa, - 0x02, 0x11, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x41, 0x75, 0x74, 0x6f, 0x63, 0x6c, 0x69, - 0x2e, 0x56, 0x31, 0xca, 0x02, 0x11, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x41, 0x75, 0x74, - 0x6f, 0x63, 0x6c, 0x69, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1d, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, - 0x5c, 0x41, 0x75, 0x74, 0x6f, 0x63, 0x6c, 0x69, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, - 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x13, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, - 0x3a, 0x3a, 0x41, 0x75, 0x74, 0x6f, 0x63, 0x6c, 0x69, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x97, 0x01, 0x0a, 0x17, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x41, 0x72, + 0x67, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x12, 0x1f, 0x0a, 0x0b, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x5f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0a, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x12, 0x18, 0x0a, 0x07, + 0x76, 0x61, 0x72, 0x61, 0x72, 0x67, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x76, + 0x61, 0x72, 0x61, 0x72, 0x67, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, + 0x61, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, + 0x61, 0x6c, 0x12, 0x25, 0x0a, 0x0e, 0x66, 0x6c, 0x61, 0x74, 0x74, 0x65, 0x6e, 0x5f, 0x66, 0x69, + 0x65, 0x6c, 0x64, 0x73, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0d, 0x66, 0x6c, 0x61, 0x74, + 0x74, 0x65, 0x6e, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x73, 0x42, 0xb9, 0x01, 0x0a, 0x15, 0x63, 0x6f, + 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x75, 0x74, 0x6f, 0x63, 0x6c, 0x69, + 0x2e, 0x76, 0x31, 0x42, 0x0c, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x50, 0x72, 0x6f, 0x74, + 0x6f, 0x50, 0x01, 0x5a, 0x2c, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, + 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x61, 0x75, 0x74, + 0x6f, 0x63, 0x6c, 0x69, 0x2f, 0x76, 0x31, 0x3b, 0x61, 0x75, 0x74, 0x6f, 0x63, 0x6c, 0x69, 0x76, + 0x31, 0xa2, 0x02, 0x03, 0x43, 0x41, 0x58, 0xaa, 0x02, 0x11, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, + 0x2e, 0x41, 0x75, 0x74, 0x6f, 0x63, 0x6c, 0x69, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x11, 0x43, 0x6f, + 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x41, 0x75, 0x74, 0x6f, 0x63, 0x6c, 0x69, 0x5c, 0x56, 0x31, 0xe2, + 0x02, 0x1d, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x41, 0x75, 0x74, 0x6f, 0x63, 0x6c, 0x69, + 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, + 0x02, 0x13, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x41, 0x75, 0x74, 0x6f, 0x63, 0x6c, + 0x69, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/api/cosmos/benchmark/module/v1/module.pulsar.go b/api/cosmos/benchmark/module/v1/module.pulsar.go index 6026b5d30281..dc3cf5171e7a 100644 --- a/api/cosmos/benchmark/module/v1/module.pulsar.go +++ b/api/cosmos/benchmark/module/v1/module.pulsar.go @@ -1361,16 +1361,27 @@ type GeneratorParams struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Seed uint64 `protobuf:"varint,1,opt,name=seed,proto3" json:"seed,omitempty"` - BucketCount uint64 `protobuf:"varint,2,opt,name=bucket_count,json=bucketCount,proto3" json:"bucket_count,omitempty"` - KeyMean uint64 `protobuf:"varint,3,opt,name=key_mean,json=keyMean,proto3" json:"key_mean,omitempty"` - KeyStdDev uint64 `protobuf:"varint,4,opt,name=key_std_dev,json=keyStdDev,proto3" json:"key_std_dev,omitempty"` - ValueMean uint64 `protobuf:"varint,6,opt,name=value_mean,json=valueMean,proto3" json:"value_mean,omitempty"` - ValueStdDev uint64 `protobuf:"varint,7,opt,name=value_std_dev,json=valueStdDev,proto3" json:"value_std_dev,omitempty"` - GenesisCount uint64 `protobuf:"varint,8,opt,name=genesis_count,json=genesisCount,proto3" json:"genesis_count,omitempty"` + // seed is the seed for the random number generator. + Seed uint64 `protobuf:"varint,1,opt,name=seed,proto3" json:"seed,omitempty"` + // bucket_count is the number of store keys to uniformly distribute genesis_count keys across. + BucketCount uint64 `protobuf:"varint,2,opt,name=bucket_count,json=bucketCount,proto3" json:"bucket_count,omitempty"` + // key_mean is the mean size (in normal distribution) of keys in each bucket. + KeyMean uint64 `protobuf:"varint,3,opt,name=key_mean,json=keyMean,proto3" json:"key_mean,omitempty"` + // key_std_dev is the standard deviation of key sizes in each bucket. + KeyStdDev uint64 `protobuf:"varint,4,opt,name=key_std_dev,json=keyStdDev,proto3" json:"key_std_dev,omitempty"` + // value_mean is the mean size (in normal distribution) of values in each bucket. + ValueMean uint64 `protobuf:"varint,6,opt,name=value_mean,json=valueMean,proto3" json:"value_mean,omitempty"` + // value_std_dev is the standard deviation of value sizes in each bucket. + ValueStdDev uint64 `protobuf:"varint,7,opt,name=value_std_dev,json=valueStdDev,proto3" json:"value_std_dev,omitempty"` + // genesis_count is the number of keys to insert in the store, distributed across all buckets. + GenesisCount uint64 `protobuf:"varint,8,opt,name=genesis_count,json=genesisCount,proto3" json:"genesis_count,omitempty"` + // insert_weight is the weight of insert operations. InsertWeight float32 `protobuf:"fixed32,9,opt,name=insert_weight,json=insertWeight,proto3" json:"insert_weight,omitempty"` + // update_weight is the weight of update operations. UpdateWeight float32 `protobuf:"fixed32,10,opt,name=update_weight,json=updateWeight,proto3" json:"update_weight,omitempty"` - GetWeight float32 `protobuf:"fixed32,12,opt,name=get_weight,json=getWeight,proto3" json:"get_weight,omitempty"` + // get_weight is the weight of get operations. + GetWeight float32 `protobuf:"fixed32,12,opt,name=get_weight,json=getWeight,proto3" json:"get_weight,omitempty"` + // delete_weight is the weight of delete operations. DeleteWeight float32 `protobuf:"fixed32,11,opt,name=delete_weight,json=deleteWeight,proto3" json:"delete_weight,omitempty"` } diff --git a/client/v2/autocli/flag/builder.go b/client/v2/autocli/flag/builder.go index 61e7c7393eef..608b59b5f58f 100644 --- a/client/v2/autocli/flag/builder.go +++ b/client/v2/autocli/flag/builder.go @@ -162,38 +162,42 @@ func (b *Builder) addMessageFlags(ctx *context.Context, flagSet *pflag.FlagSet, messageBinder.hasOptional = true } - field := fields.ByName(protoreflect.Name(arg.ProtoField)) - if field == nil { - return nil, fmt.Errorf("can't find field %s on %s", arg.ProtoField, messageType.Descriptor().FullName()) + if arg.FlattenFields { + msgFields := messageType.Descriptor().Fields() + for j := range msgFields.Len() { // todo: this loop can be removed if msgFields.ByName(arg.protoField) + field := msgFields.Get(j) + if arg.ProtoField == string(field.Name()) { + msgType := messageType.New().Get(field).Message() + innerFields := msgType.Descriptor().Fields() + for k := range innerFields.Len() { + err := b.addFieldBindingToArgs(ctx, messageBinder, k, innerFields) + if err != nil { + return nil, err + } + } + break + } + } + continue } - _, hasValue, err := b.addFieldFlag( - ctx, - messageBinder.positionalFlagSet, - field, - &autocliv1.FlagOptions{Name: fmt.Sprintf("%d", i)}, - namingOptions{}, - ) + err := b.addFieldBindingToArgs(ctx, messageBinder, i, fields) if err != nil { return nil, err } - - messageBinder.positionalArgs = append(messageBinder.positionalArgs, fieldBinding{ - field: field, - hasValue: hasValue, - }) } + totalArgs := len(messageBinder.positionalArgs) switch { case messageBinder.hasVarargs: - messageBinder.CobraArgs = cobra.MinimumNArgs(positionalArgsLen - 1) - messageBinder.mandatoryArgUntil = positionalArgsLen - 1 + messageBinder.CobraArgs = cobra.MinimumNArgs(totalArgs - 1) + messageBinder.mandatoryArgUntil = totalArgs - 1 case messageBinder.hasOptional: - messageBinder.CobraArgs = cobra.RangeArgs(positionalArgsLen-1, positionalArgsLen) - messageBinder.mandatoryArgUntil = positionalArgsLen - 1 + messageBinder.CobraArgs = cobra.RangeArgs(totalArgs-1, totalArgs) + messageBinder.mandatoryArgUntil = totalArgs - 1 default: - messageBinder.CobraArgs = cobra.ExactArgs(positionalArgsLen) - messageBinder.mandatoryArgUntil = positionalArgsLen + messageBinder.CobraArgs = cobra.ExactArgs(totalArgs) + messageBinder.mandatoryArgUntil = totalArgs } // validate flag options @@ -273,6 +277,34 @@ func (b *Builder) addMessageFlags(ctx *context.Context, flagSet *pflag.FlagSet, return messageBinder, nil } +// addFieldBindingToArgs adds a fieldBinding for a positional argument to the message binder. +// The fieldBinding is appended to the positional arguments list in the message binder. +func (b *Builder) addFieldBindingToArgs(ctx *context.Context, messageBinder *MessageBinder, i int, fields protoreflect.FieldDescriptors) error { + field := fields.Get(i) + if field == nil { + return errors.New("can't find filed of inner message") // TODO: this should show names + //return fmt.Errorf("can't find field %s on %s", arg.ProtoField, messageType.Descriptor().FullName()) + } + + _, hasValue, err := b.addFieldFlag( + ctx, + messageBinder.positionalFlagSet, + field, + &autocliv1.FlagOptions{Name: fmt.Sprintf("%d", len(messageBinder.positionalArgs))}, + namingOptions{}, + ) + if err != nil { + return err + } + + messageBinder.positionalArgs = append(messageBinder.positionalArgs, fieldBinding{ + field: field, + hasValue: hasValue, + }) + + return nil +} + // bindPageRequest create a flag for pagination func (b *Builder) bindPageRequest(ctx *context.Context, flagSet *pflag.FlagSet, field protoreflect.FieldDescriptor) (HasValue, error) { return b.addMessageFlags( diff --git a/client/v2/autocli/flag/messager_binder.go b/client/v2/autocli/flag/messager_binder.go index 46a28baa285a..a7d1320d8cb8 100644 --- a/client/v2/autocli/flag/messager_binder.go +++ b/client/v2/autocli/flag/messager_binder.go @@ -2,6 +2,7 @@ package flag import ( "fmt" + "strings" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -65,10 +66,25 @@ func (m MessageBinder) Bind(msg protoreflect.Message, positionalArgs []string) e } } + msgName := msg.Descriptor().Name() // bind positional arg values to the message - for _, arg := range m.positionalArgs { - if err := arg.bind(msg); err != nil { - return err + for i := 0; i < len(m.positionalArgs); i++ { + arg := m.positionalArgs[i] + if msgName == arg.field.Parent().Name() { + if err := arg.bind(msg); err != nil { + return err + } + } else { + name := protoreflect.Name(strings.ToLower(string(arg.field.Parent().Name()))) + innerMsg := msg.New().Get(msg.Descriptor().Fields().ByName(name)).Message().New() + for j := 0; j < innerMsg.Descriptor().Fields().Len(); j++ { + arg = m.positionalArgs[j+i] + if err := arg.bind(innerMsg); err != nil { + return err + } + } + msg.Set(msg.Descriptor().Fields().ByName(name), protoreflect.ValueOfMessage(innerMsg)) + i += innerMsg.Descriptor().Fields().Len() } } @@ -93,6 +109,7 @@ type fieldBinding struct { field protoreflect.FieldDescriptor } +// TODO: how to bind inner messages func (f fieldBinding) bind(msg protoreflect.Message) error { field := f.field val, err := f.hasValue.Get(msg.NewField(field)) diff --git a/client/v2/go.mod b/client/v2/go.mod index f08d0e2730cd..5f66b3ed0253 100644 --- a/client/v2/go.mod +++ b/client/v2/go.mod @@ -180,6 +180,7 @@ replace github.com/cosmos/cosmos-sdk => ./../../ // TODO remove post spinning out all modules replace ( + cosmossdk.io/api => ./../../api cosmossdk.io/store => ./../../store cosmossdk.io/x/bank => ./../../x/bank cosmossdk.io/x/gov => ./../../x/gov diff --git a/proto/cosmos/autocli/v1/options.proto b/proto/cosmos/autocli/v1/options.proto index 8160a6e0276e..a719c8016362 100644 --- a/proto/cosmos/autocli/v1/options.proto +++ b/proto/cosmos/autocli/v1/options.proto @@ -140,4 +140,7 @@ message PositionalArgDescriptor { // optional makes the last positional parameter optional. // Note: It is mutually exclusive with varargs. bool optional = 3; + + // TODO: doc + bool flatten_fields = 14; } diff --git a/simapp/go.mod b/simapp/go.mod index 7162e4f29919..957ac8706212 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -250,6 +250,7 @@ require ( // SimApp on main always tests the latest extracted SDK modules importing the sdk replace ( + cosmossdk.io/api => ../api cosmossdk.io/client/v2 => ../client/v2 cosmossdk.io/collections => ../collections cosmossdk.io/indexer/postgres => ../indexer/postgres