@@ -15,122 +15,24 @@ import (
15
15
type GenerateCmd struct {}
16
16
17
17
const (
18
- flagLanguage = "language"
19
- flagOutputDir = "output-dir"
18
+ flagLanguage = "language"
19
+ flagOutputDir = "output-dir"
20
+ argSchema = "schema"
21
+ argTitleSchema = "schema"
20
22
)
21
23
22
24
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 )
126
28
cc .AddStringFlag (flagLanguage , "l" , "" , true , "programming language to use for the generated code" )
127
29
cc .AddStringFlag (flagOutputDir , "o" , "." , false , "output directory for the generated files" )
128
- cc .SetPositionalArgCount ( 1 , 1 )
30
+ cc .AddStringArg ( argSchema , argTitleSchema )
129
31
return nil
130
32
}
131
33
132
34
func (g GenerateCmd ) Exec (ctx context.Context , ec plug.ExecContext ) error {
133
- schemaPath := ec .Args ()[ 0 ]
35
+ schemaPath := ec .GetStringArg ( argSchema )
134
36
language := ec .Props ().GetString (flagLanguage )
135
37
outputDir := ec .Props ().GetString (flagOutputDir )
136
38
_ , stop , err := ec .ExecuteBlocking (ctx , func (ctx context.Context , sp clc.Spinner ) (any , error ) {
0 commit comments