Skip to content

Commit

Permalink
Enable turning off the file header
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Huxtable committed Mar 6, 2018
1 parent e7468fd commit 6df5af4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/protostub/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ var generateCmd = &cobra.Command{
panic(err)
}

if err := gen.Gen(mf, p); err != nil {
if err := gen.Gen(mf, p, true); err != nil {
panic(err)
}
},
Expand Down
10 changes: 6 additions & 4 deletions gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ type generator struct {
// used to generate mypy stubs from proto data

// Gen writes a mypy type stub to w, generated from the data in p
func Gen(w io.Writer, p *protostub.ProtoData) error {
func Gen(w io.Writer, p *protostub.ProtoData, header bool) error {
gen := &generator{0, bufio.NewWriter(w)}

gen.bw.WriteString(fmt.Sprintf("# Generated by protostub on %s\n", time.Now().Format("Mon Jan 2 15:04:05 -0700 MST 2006")))
gen.bw.WriteString("# https://github.com/arachnys/protostub\n")
gen.bw.WriteString("# Do not modify\n")
if header {
gen.bw.WriteString(fmt.Sprintf("# Generated by protostub on %s\n", time.Now().Format("Mon Jan 2 15:04:05 -0700 MST 2006")))
gen.bw.WriteString("# https://github.com/arachnys/protostub\n")
gen.bw.WriteString("# Do not modify\n")
}

for _, i := range p.Types {
if err := gen.gen(i); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion tests/gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestGeneration(t *testing.T) {

buf := bytes.NewBuffer(nil)

if err := gen.Gen(buf, p); err != nil {
if err := gen.Gen(buf, p, false); err != nil {
t.Fatal(err)
}

Expand Down

0 comments on commit 6df5af4

Please sign in to comment.