Skip to content

Commit

Permalink
Optimize code logic
Browse files Browse the repository at this point in the history
Signed-off-by: weiyang <[email protected]>
  • Loading branch information
wy-z committed Sep 25, 2017
1 parent 3b3b210 commit 11b5a47
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 85 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ GLOBAL OPTIONS:
--expression EXPR, --expr EXPR (required) type expression EXPR
--proto-package PP, --pp PP (required) proto package PP
--proto-file PF, --pf PF load messages from proto file PF
--ignore-json-tag ignore json tag (default: true)
--help, -h show help
--version, -v print the version
```
Expand Down
12 changes: 8 additions & 4 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type cliOpts struct {
TypeExpr string
ProtoPkg string
ProtoFile string
IgnoreJSONTag bool
IgnoreJSONTag *bool
}

//Run runs tproto
Expand Down Expand Up @@ -47,8 +47,8 @@ func Run(version string) {
},
cli.BoolFlag{
Name: "ignore-json-tag",
Usage: "ignore json tag",
Destination: &opts.IgnoreJSONTag,
Usage: "ignore json tag (default: true)",
Destination: opts.IgnoreJSONTag,
},
}
app.Action = func(c *cli.Context) (err error) {
Expand All @@ -59,7 +59,11 @@ func Run(version string) {

parser := tproto.NewParser()
parserOpts := tproto.DefaultParserOptions
parserOpts.IgnoreJSONTag = opts.IgnoreJSONTag
if opts.IgnoreJSONTag != nil {
parserOpts.IgnoreJSONTag = *opts.IgnoreJSONTag
} else {
parserOpts.IgnoreJSONTag = true
}
parser.Options(parserOpts)

if opts.ProtoFile != "" {
Expand Down
40 changes: 20 additions & 20 deletions samples/source/basic_types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ syntax = "proto3";
package samples;

message BasicTypes {
bool bool_field = 1;
bytes byte_field = 2;
double complex128_field = 3;
float complex64_field = 4;
float float32_field = 5;
double float64_field = 6;
int32 int16_field = 7;
int32 int32_field = 8;
int64 int64_field = 9;
int32 int8_field = 10;
int64 int_field = 11;
bytes rune_field = 12;
string string_field = 13;
string time_field = 14;
int32 uint16_field = 15;
int32 uint32_field = 16;
int64 uint64_field = 17;
int32 uint8_field = 18;
int64 uint_field = 19;
int64 uintptr_field = 20;
bool BoolField = 1;
bytes ByteField = 2;
double Complex128Field = 3;
float Complex64Field = 4;
float Float32Field = 5;
double Float64Field = 6;
int32 Int16Field = 7;
int32 Int32Field = 8;
int64 Int64Field = 9;
int32 Int8Field = 10;
int64 IntField = 11;
bytes RuneField = 12;
string StringField = 13;
string TimeField = 14;
int32 Uint16Field = 15;
int32 Uint32Field = 16;
int64 Uint64Field = 17;
int32 Uint8Field = 18;
int64 UintField = 19;
int64 UintptrField = 20;
}

46 changes: 23 additions & 23 deletions samples/source/normal_struct.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@ syntax = "proto3";
package samples;

message BasicTypes {
bool bool_field = 1;
bytes byte_field = 2;
double complex128_field = 3;
float complex64_field = 4;
float float32_field = 5;
double float64_field = 6;
int32 int16_field = 7;
int32 int32_field = 8;
int64 int64_field = 9;
int32 int8_field = 10;
int64 int_field = 11;
bytes rune_field = 12;
string string_field = 13;
string time_field = 14;
int32 uint16_field = 15;
int32 uint32_field = 16;
int64 uint64_field = 17;
int32 uint8_field = 18;
int64 uint_field = 19;
int64 uintptr_field = 20;
bool BoolField = 1;
bytes ByteField = 2;
double Complex128Field = 3;
float Complex64Field = 4;
float Float32Field = 5;
double Float64Field = 6;
int32 Int16Field = 7;
int32 Int32Field = 8;
int64 Int64Field = 9;
int32 Int8Field = 10;
int64 IntField = 11;
bytes RuneField = 12;
string StringField = 13;
string TimeField = 14;
int32 Uint16Field = 15;
int32 Uint32Field = 16;
int64 Uint64Field = 17;
int32 Uint8Field = 18;
int64 UintField = 19;
int64 UintptrField = 20;
}
message NormalStruct {
BasicTypes basic_types = 1;
string create = 2;
int64 number = 3;
BasicTypes BasicTypes = 1;
string Create = 2;
int64 Number = 3;
}

18 changes: 9 additions & 9 deletions samples/source/struct_with_anonymous_field.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ syntax = "proto3";
package samples;

message StructWithAnonymousField {
repeated StructWithAnonymousField_AnonymousArray_Elt anonymous_array = 1;
map <string,StructWithAnonymousField_AnonymousMap_Elt> anonymous_map = 2;
StructWithAnonymousField_AnonymousStruct anonymous_struct = 3;
repeated StructWithAnonymousField_AnonymousArray_Elt AnonymousArray = 1;
map <string,StructWithAnonymousField_AnonymousMap_Elt> AnonymousMap = 2;
StructWithAnonymousField_AnonymousStruct AnonymousStruct = 3;
}
message StructWithAnonymousField_AnonymousArray_Elt {
bool bool_field = 1;
string string_field = 2;
bool BoolField = 1;
string StringField = 2;
}
message StructWithAnonymousField_AnonymousMap_Elt {
bool bool_field = 1;
string string_field = 2;
bool BoolField = 1;
string StringField = 2;
}
message StructWithAnonymousField_AnonymousStruct {
bool bool_field = 1;
string string_field = 2;
bool BoolField = 1;
string StringField = 2;
}

2 changes: 1 addition & 1 deletion samples/source/struct_with_circular_reference.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ syntax = "proto3";
package samples;

message StructWithCircularReference {
StructWithCircularReference circular_reference = 1;
StructWithCircularReference CircularReference = 1;
}

52 changes: 25 additions & 27 deletions samples/source/struct_with_inheritance.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,34 @@ syntax = "proto3";
package samples;

message BasicTypes {
bool bool_field = 1;
bytes byte_field = 2;
double complex128_field = 3;
float complex64_field = 4;
float float32_field = 5;
double float64_field = 6;
int32 int16_field = 7;
int32 int32_field = 8;
int64 int64_field = 9;
int32 int8_field = 10;
int64 int_field = 11;
bytes rune_field = 12;
string string_field = 13;
string time_field = 14;
int32 uint16_field = 15;
int32 uint32_field = 16;
int64 uint64_field = 17;
int32 uint8_field = 18;
int64 uint_field = 19;
int64 uintptr_field = 20;
bool BoolField = 1;
bytes ByteField = 2;
double Complex128Field = 3;
float Complex64Field = 4;
float Float32Field = 5;
double Float64Field = 6;
int32 Int16Field = 7;
int32 Int32Field = 8;
int64 Int64Field = 9;
int32 Int8Field = 10;
int64 IntField = 11;
bytes RuneField = 12;
string StringField = 13;
string TimeField = 14;
int32 Uint16Field = 15;
int32 Uint32Field = 16;
int64 Uint64Field = 17;
int32 Uint8Field = 18;
int64 UintField = 19;
int64 UintptrField = 20;
}
message NormalStruct {
BasicTypes basic_types = 1;
string create = 2;
int64 number = 3;
BasicTypes BasicTypes = 1;
string Create = 2;
int64 Number = 3;
}
message StructWithCircularReference {
StructWithCircularReference circular_reference = 1;
}
message StructWithInheritance {
NormalStruct normal_struct = 1;
StructWithCircularReference CircularReference = 1;
}
message StructWithInheritance {}

4 changes: 3 additions & 1 deletion samples/source/struct_with_no_export_field.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ syntax = "proto3";

package samples;

message StructWithNoExportField {}
message StructWithNoExportField {
string Create = 1;
}

3 changes: 3 additions & 0 deletions tproto/tproto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ type TProtoTestSuite struct {

func (s *TProtoTestSuite) SetupTest() {
s.parser = tproto.NewParser()
parserOpts := tproto.DefaultParserOptions
parserOpts.IgnoreJSONTag = true
s.parser.Options(parserOpts)
s.pkg = "github.com/wy-z/tproto/samples"
}

Expand Down

0 comments on commit 11b5a47

Please sign in to comment.