Skip to content

Commit ddad5a2

Browse files
committed
Implemented flag for listing all supported languages
1 parent 9198200 commit ddad5a2

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

README.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,23 +125,16 @@ Sometimes your schema will have a nested schema, where one object contains anoth
125125

126126
This will generate both Car.go and Tire.go, each containing the relevant data model and associated functions. The "Car" model will actually reference the "Tire" model. Note that if there are multiple schemas with the same title, an error will be given. You _must_ uniquely name your models.
127127

128-
That's cool, but not everyone uses Go. What about other languages? Using `-l` lists all supported languages.
128+
That's cool, but not everyone uses Go. What about other languages? Using `-a` lists all supported languages.
129129

130-
presilo -l
130+
presilo -a
131131

132-
All supported languages have some form of "package" notion, which should be specified by the `-p` flag. For instance:
132+
All supported languages have some form of "module" notion, which should be specified by the `-m` flag. For instance:
133133

134-
presilo -l go -p awesome schema.json
134+
presilo -l go -m awesome schema.json
135135

136136
Will make it so that instead of `package main`, the generated files will be listed as `package awesome`. Languages with nested package names (Java, Ruby, C#) will accept the dot-notation to separate package names (`com.awesome.project`, for example). If you give nested package names and tell `presilo` to generate a schema for a language which does not support them, it will give you an error.
137137

138-
How do I update a schema?
139-
====
140-
141-
Sometimes your schemas aren't perfect, and new features will introduce new fields in existing schemas. You may have even inserted code into the generated data model. If `presilo` finds an existing code file when generating from a schema, it will try to merge its changes into the new file. This merge will first find-and-replace variable- and class-names in the generated file. If there are getters or setters for a variable that has been renamed, the old ones will be deleted wholesale. Then it will rewrite methods that would be created by it (getters, setters, and constructors, mainly). All other code / comments are left unchanged.
142-
143-
Note that this still means that downstream consumers of the schema will need to be manually updated. Updating the schema will _not_ update all of your business logic! Just the data model. And, you'll lose any code that you've added to the getters or setters.
144-
145138
Isn't there something else which does this?
146139
====
147140

RunSettings.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type RunSettings struct {
1111
OutputPath string
1212
Language string
1313
Module string
14+
ListLanguages bool
1415
splitFiles bool
1516
}
1617

@@ -34,10 +35,15 @@ func ParseRunSettings() (*RunSettings, error) {
3435
flag.StringVar(&ret.Language, "l", "go", "Language for the generated files")
3536
flag.StringVar(&ret.OutputPath, "o", "./", "Optional destination directory for generated files")
3637
flag.StringVar(&ret.Module, "m", "main", "Module to use for the generated files")
38+
flag.BoolVar(&ret.ListLanguages, "a", false, "Lists all supported languages")
3739

3840
flag.Parse()
3941
ret.InputPath = flag.Arg(0)
4042

43+
if(ret.ListLanguages) {
44+
return ret, nil
45+
}
46+
4147
if len(ret.InputPath) == 0 {
4248
return nil, errors.New("Input path not specified")
4349
}

main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ func main() {
1818
return
1919
}
2020

21+
if(settings.ListLanguages) {
22+
printLanguages()
23+
return
24+
}
25+
2126
settings.OutputPath, err = prepareOutputPath(settings.OutputPath)
2227
if err != nil {
2328
exitWith("Unable to create output directory: %s\n", err)
@@ -37,6 +42,13 @@ func main() {
3742
}
3843
}
3944

45+
func printLanguages() {
46+
47+
for _, language := range SUPPORTED_LANGUAGES {
48+
fmt.Println(language)
49+
}
50+
}
51+
4052
func exitWith(message string, err error) {
4153

4254
errorMessage := fmt.Sprintf(message, err.Error())

0 commit comments

Comments
 (0)