Merge pull request #43 from gfanton/feature/add-all-argument
Feature/add all argument
This commit is contained in:
commit
5a65b0fca4
18
encoder.go
18
encoder.go
@ -37,7 +37,7 @@ type Ast struct {
|
||||
Environment []string `json:"environment"`
|
||||
}
|
||||
|
||||
func NewGenericTemplateBasedEncoder(templateDir string, service *descriptor.ServiceDescriptorProto, file *descriptor.FileDescriptorProto, debug bool, destinationDir string) (e *GenericTemplateBasedEncoder) {
|
||||
func NewGenericServiceTemplateBasedEncoder(templateDir string, service *descriptor.ServiceDescriptorProto, file *descriptor.FileDescriptorProto, debug bool, destinationDir string) (e *GenericTemplateBasedEncoder) {
|
||||
e = &GenericTemplateBasedEncoder{
|
||||
service: service,
|
||||
file: file,
|
||||
@ -53,6 +53,22 @@ func NewGenericTemplateBasedEncoder(templateDir string, service *descriptor.Serv
|
||||
return
|
||||
}
|
||||
|
||||
func NewGenericTemplateBasedEncoder(templateDir string, file *descriptor.FileDescriptorProto, debug bool, destinationDir string) (e *GenericTemplateBasedEncoder) {
|
||||
e = &GenericTemplateBasedEncoder{
|
||||
service: nil,
|
||||
file: file,
|
||||
templateDir: templateDir,
|
||||
debug: debug,
|
||||
destinationDir: destinationDir,
|
||||
}
|
||||
|
||||
if debug {
|
||||
log.Printf("new encoder: file=%q template-dir=%q", file.GetName(), templateDir)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (e *GenericTemplateBasedEncoder) templates() ([]string, error) {
|
||||
filenames := []string{}
|
||||
|
||||
|
18
main.go
18
main.go
@ -32,6 +32,7 @@ func main() {
|
||||
templateDir := "./templates"
|
||||
destinationDir := "."
|
||||
debug := false
|
||||
all := false
|
||||
if parameter := g.Request.GetParameter(); parameter != "" {
|
||||
for _, param := range strings.Split(parameter, ",") {
|
||||
parts := strings.Split(param, "=")
|
||||
@ -55,6 +56,15 @@ func main() {
|
||||
log.Printf("Err: invalid value for debug: %q", parts[1])
|
||||
}
|
||||
break
|
||||
case "all":
|
||||
switch strings.ToLower(parts[1]) {
|
||||
case "true", "t":
|
||||
all = true
|
||||
case "false", "f":
|
||||
default:
|
||||
log.Printf("Err: invalid value for debug: %q", parts[1])
|
||||
}
|
||||
break
|
||||
default:
|
||||
log.Printf("Err: unknown parameter: %q", param)
|
||||
}
|
||||
@ -63,8 +73,14 @@ func main() {
|
||||
|
||||
// Generate the encoders
|
||||
for _, file := range g.Request.GetProtoFile() {
|
||||
if all {
|
||||
encoder := NewGenericTemplateBasedEncoder(templateDir, file, debug, destinationDir)
|
||||
g.Response.File = append(g.Response.File, encoder.Files()...)
|
||||
continue
|
||||
}
|
||||
|
||||
for _, service := range file.GetService() {
|
||||
encoder := NewGenericTemplateBasedEncoder(templateDir, service, file, debug, destinationDir)
|
||||
encoder := NewGenericServiceTemplateBasedEncoder(templateDir, service, file, debug, destinationDir)
|
||||
g.Response.File = append(g.Response.File, encoder.Files()...)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user