Skip to content

Commit

Permalink
move main to allow other projects generate the plugin, and thus vendo…
Browse files Browse the repository at this point in the history
…r it (#19)
  • Loading branch information
yuval-k authored Dec 6, 2018
1 parent 798acc5 commit fb669c9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
22 changes: 1 addition & 21 deletions cmd/protoc-gen-solo-kit/main.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
package main

import (
"log"
"os"

"github.com/pseudomuto/protokit"
"github.com/solo-io/solo-kit/pkg/code-generator"
)

func main() {
outputDescriptors := os.Getenv("OUTPUT_DESCRIPTORS") == "1"
mergeOutputDescriptors := os.Getenv("OUTPUT_MERGED_DESCRIPTORS_FILE")
plugin := &code_generator.Plugin{OutputDescriptors: outputDescriptors, MergeDescriptors: mergeOutputDescriptors}
// use this to debug without running protoc
if descriptorsFile := os.Getenv("USE_DESCRIPTORS"); descriptorsFile != "" {
// descriptorsFile e.g.: "projects/supergloo/api/v1/project.json.descriptors"
f, err := os.Open(descriptorsFile)
if err != nil {
log.Fatal(err)
}
if err := protokit.RunPluginWithIO(plugin, f, os.Stdout); err != nil {
log.Fatal(err)
}
}
if err := protokit.RunPlugin(plugin); err != nil {
log.Fatal(err)
}
code_generator.Main()
}
28 changes: 28 additions & 0 deletions pkg/code-generator/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package code_generator

import (
"log"
"os"

"github.com/pseudomuto/protokit"
)

func Main() {
outputDescriptors := os.Getenv("OUTPUT_DESCRIPTORS") == "1"
mergeOutputDescriptors := os.Getenv("OUTPUT_MERGED_DESCRIPTORS_FILE")
plugin := &Plugin{OutputDescriptors: outputDescriptors, MergeDescriptors: mergeOutputDescriptors}
// use this to debug without running protoc
if descriptorsFile := os.Getenv("USE_DESCRIPTORS"); descriptorsFile != "" {
// descriptorsFile e.g.: "projects/supergloo/api/v1/project.json.descriptors"
f, err := os.Open(descriptorsFile)
if err != nil {
log.Fatal(err)
}
if err := protokit.RunPluginWithIO(plugin, f, os.Stdout); err != nil {
log.Fatal(err)
}
}
if err := protokit.RunPlugin(plugin); err != nil {
log.Fatal(err)
}
}

0 comments on commit fb669c9

Please sign in to comment.