Skip to content

Commit 6df5af4

Browse files
author
Will Huxtable
committed
Enable turning off the file header
1 parent e7468fd commit 6df5af4

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

cmd/protostub/cmd/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ var generateCmd = &cobra.Command{
6666
panic(err)
6767
}
6868

69-
if err := gen.Gen(mf, p); err != nil {
69+
if err := gen.Gen(mf, p, true); err != nil {
7070
panic(err)
7171
}
7272
},

gen/gen.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ type generator struct {
2121
// used to generate mypy stubs from proto data
2222

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

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

3133
for _, i := range p.Types {
3234
if err := gen.gen(i); err != nil {

tests/gen_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestGeneration(t *testing.T) {
5454

5555
buf := bytes.NewBuffer(nil)
5656

57-
if err := gen.Gen(buf, p); err != nil {
57+
if err := gen.Gen(buf, p, false); err != nil {
5858
t.Fatal(err)
5959
}
6060

0 commit comments

Comments
 (0)