Skip to content

Commit 049a4a3

Browse files
author
kmetin
committed
fix PR comments
1 parent f8e4162 commit 049a4a3

File tree

2 files changed

+107
-107
lines changed

2 files changed

+107
-107
lines changed

base/commands/serializer/const.go

+98
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,101 @@ var fixedSizeTypes = map[string]string{
6363
"float32": "0.0",
6464
"float64": "0.0",
6565
}
66+
67+
const longHelp = `Generates compact serializer from the given schema and for the given programming language.
68+
You can use this command to automatically generate compact serializers instead of implementing them.
69+
See: https://docs.hazelcast.com/hazelcast/latest/serialization/compact-serialization#implementing-compactserializer
70+
71+
A schema allows you to:
72+
- describe the contents of a compact class using supported field types
73+
- import other schema
74+
- specify a namespaces for schema files and reference other namespaces
75+
- define cyclic references between classes
76+
- reference classes that are not present in the given schemas
77+
78+
A schema is written in YAML.Schema format is given below:
79+
80+
81+
namespace: <namespace of the class>
82+
# note that other schema files can be imported with relative path to this yaml file
83+
imports:
84+
- someOtherSchema.yaml
85+
# All objects in this file will share the same namespace.
86+
classes:
87+
- name: <name of the class>
88+
fields:
89+
- name: <field name>
90+
type: <field type>
91+
external: bool # to mark external types (external to this yaml file)
92+
93+
94+
- namespace: Used for logical grouping of classes. Typically, for every namespace, you will have a schema file.
95+
Namespace is optional. If not provided, the classes will be generated at global namespace (no namespace).
96+
The user should provide the language specific best practice when using the namespace.
97+
The tool will use the namespace while generating code if provided.
98+
99+
- imports: Used to import other schema files.
100+
The type definitions in the imported yaml schemas can be used within this yaml file.
101+
Cyclic imports will be checked and handled properly.
102+
For this version of the tool, an import can only be a single file name
103+
and the tool will assume all yaml files imported will be in the same directory as the importing schema file.
104+
105+
- classes: Used to define classes in the schema
106+
- name: Name of the class
107+
- fields: Fields of the class
108+
- name: Name of the field
109+
- type: Type of the field.
110+
Normally you should refer to another class as namespace.classname.
111+
You can use a class without namespace when the class is defined in the same schema yaml file.
112+
type can be one of the following:
113+
- boolean
114+
- boolean[]
115+
- int8
116+
- int8[]
117+
- int16
118+
- int16[]
119+
- int32
120+
- int32[]
121+
- int64
122+
- int64[]
123+
- float32
124+
- float32[]
125+
- float64
126+
- float64[]
127+
- string
128+
- string[]
129+
- date
130+
- date[]
131+
- time
132+
- time[]
133+
- timestamp
134+
- timestamp[]
135+
- timestampWithTimezone
136+
- timestampWithTimezone[]
137+
- nullableBoolean
138+
- nullableBoolean[]
139+
- nullableInt8
140+
- nullableInt8[]
141+
- nullableInt16
142+
- nullableInt16[]
143+
- nullableInt32
144+
- nullableInt32[]
145+
- nullableInt64
146+
- nullableInt64[]
147+
- nullableFloat32
148+
- nullableFloat32[]
149+
- nullableFloat64
150+
- nullableFloat64[]
151+
- <OtherCompactClass[]>
152+
- external: Used to mark if the type is external.
153+
If a field is external, the tool will not check if it is imported and available.
154+
External types are managed by the user and not generated by the tool.
155+
156+
The serializer of an external field can be a custom serializer which is hand written,
157+
the zero-config serializer for Java and .NET, or previously generated using the tool.
158+
This flag will enable such mixed use cases.
159+
160+
In generated code, external types are imported exactly what as the "type" of the field,
161+
hence for languages like Java the user should enter the full package name together with the class.
162+
E.g. type: com.app1.dto.Address
163+
`

base/commands/serializer/generate.go

+9-107
Original file line numberDiff line numberDiff line change
@@ -15,122 +15,24 @@ import (
1515
type GenerateCmd struct{}
1616

1717
const (
18-
flagLanguage = "language"
19-
flagOutputDir = "output-dir"
18+
flagLanguage = "language"
19+
flagOutputDir = "output-dir"
20+
argSchema = "schema"
21+
argTitleSchema = "schema"
2022
)
2123

2224
func (g GenerateCmd) Init(cc plug.InitContext) error {
23-
cc.SetCommandUsage("generate [schema] [flags]")
24-
short := `
25-
Generates compact serializer from the given schema and for the given programming language. (BETA)
26-
`
27-
long := `
28-
Generates compact serializer from the given schema and for the given programming language.
29-
You can use this command to automatically generate compact serializers instead of implementing them.
30-
See: https://docs.hazelcast.com/hazelcast/latest/serialization/compact-serialization#implementing-compactserializer
31-
32-
A schema allows you to:
33-
- describe the contents of a compact class using supported field types
34-
- import other schema
35-
- specify a namespaces for schema files and reference other namespaces
36-
- define cyclic references between classes
37-
- reference classes that are not present in the given schemas
38-
39-
A schema is written in YAML.Schema format is given below:
40-
41-
42-
namespace: <namespace of the class>
43-
# note that other schema files can be imported with relative path to this yaml file
44-
imports:
45-
- someOtherSchema.yaml
46-
# All objects in this file will share the same namespace.
47-
classes:
48-
- name: <name of the class>
49-
fields:
50-
- name: <field name>
51-
type: <field type>
52-
external: bool # to mark external types (external to this yaml file)
53-
54-
55-
- namespace: Used for logical grouping of classes. Typically, for every namespace, you will have a schema file.
56-
Namespace is optional. If not provided, the classes will be generated at global namespace (no namespace).
57-
The user should provide the language specific best practice when using the namespace.
58-
The tool will use the namespace while generating code if provided.
59-
60-
- imports: Used to import other schema files.
61-
The type definitions in the imported yaml schemas can be used within this yaml file.
62-
Cyclic imports will be checked and handled properly.
63-
For this version of the tool, an import can only be a single file name
64-
and the tool will assume all yaml files imported will be in the same directory as the importing schema file.
65-
66-
- classes: Used to define classes in the schema
67-
- name: Name of the class
68-
- fields: Fields of the class
69-
- name: Name of the field
70-
- type: Type of the field.
71-
Normally you should refer to another class as namespace.classname.
72-
You can use a class without namespace when the class is defined in the same schema yaml file.
73-
type can be one of the following:
74-
- boolean
75-
- boolean[]
76-
- int8
77-
- int8[]
78-
- int16
79-
- int16[]
80-
- int32
81-
- int32[]
82-
- int64
83-
- int64[]
84-
- float32
85-
- float32[]
86-
- float64
87-
- float64[]
88-
- string
89-
- string[]
90-
- date
91-
- date[]
92-
- time
93-
- time[]
94-
- timestamp
95-
- timestamp[]
96-
- timestampWithTimezone
97-
- timestampWithTimezone[]
98-
- nullableBoolean
99-
- nullableBoolean[]
100-
- nullableInt8
101-
- nullableInt8[]
102-
- nullableInt16
103-
- nullableInt16[]
104-
- nullableInt32
105-
- nullableInt32[]
106-
- nullableInt64
107-
- nullableInt64[]
108-
- nullableFloat32
109-
- nullableFloat32[]
110-
- nullableFloat64
111-
- nullableFloat64[]
112-
- <OtherCompactClass[]>
113-
- external: Used to mark if the type is external.
114-
If a field is external, the tool will not check if it is imported and available.
115-
External types are managed by the user and not generated by the tool.
116-
117-
The serializer of an external field can be a custom serializer which is hand written,
118-
the zero-config serializer for Java and .NET, or previously generated using the tool.
119-
This flag will enable such mixed use cases.
120-
121-
In generated code, external types are imported exactly what as the "type" of the field,
122-
hence for languages like Java the user should enter the full package name together with the class.
123-
E.g. type: com.app1.dto.Address
124-
`
125-
cc.SetCommandHelp(long, short)
25+
cc.SetCommandUsage("generate")
26+
short := `Generates compact serializer from the given schema and for the given programming language. (BETA)`
27+
cc.SetCommandHelp(longHelp, short)
12628
cc.AddStringFlag(flagLanguage, "l", "", true, "programming language to use for the generated code")
12729
cc.AddStringFlag(flagOutputDir, "o", ".", false, "output directory for the generated files")
128-
cc.SetPositionalArgCount(1, 1)
30+
cc.AddStringArg(argSchema, argTitleSchema)
12931
return nil
13032
}
13133

13234
func (g GenerateCmd) Exec(ctx context.Context, ec plug.ExecContext) error {
133-
schemaPath := ec.Args()[0]
35+
schemaPath := ec.GetStringArg(argSchema)
13436
language := ec.Props().GetString(flagLanguage)
13537
outputDir := ec.Props().GetString(flagOutputDir)
13638
_, stop, err := ec.ExecuteBlocking(ctx, func(ctx context.Context, sp clc.Spinner) (any, error) {

0 commit comments

Comments
 (0)