OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 package main | 5 package main |
6 | 6 |
7 import ( | 7 import ( |
8 "bufio" | 8 "bufio" |
9 "flag" | 9 "flag" |
10 "fmt" | 10 "fmt" |
11 "io" | 11 "io" |
12 "os" | 12 "os" |
13 "sort" | 13 "sort" |
(...skipping 20 matching lines...) Expand all Loading... | |
34 | 34 |
35 //go:generate <protoc command> | 35 //go:generate <protoc command> |
36 //go:generate proto-gae -type MessageType -type OtherMessageType | 36 //go:generate proto-gae -type MessageType -type OtherMessageType |
37 | 37 |
38 This will produce a new file which implements the ToProperty and FromProperty | 38 This will produce a new file which implements the ToProperty and FromProperty |
39 methods for the named types. | 39 methods for the named types. |
40 | 40 |
41 Options: | 41 Options: |
42 ` | 42 ` |
43 | 43 |
44 const copyright = `// Copyright 2016 The Chromium Authors. All rights reserved. | 44 const copyright = `// Copyright 2016 The LUCI Authors. All rights reserved. |
M-A Ruel
2016/05/30 18:28:23
Unrelated to this CL but it should take time.Now()
| |
45 // Use of this source code is governed by a BSD-style license that can be | 45 // Use of this source code is governed under the Apache License, Version 2.0 |
46 // found in the LICENSE file. | 46 // that can be found in the LICENSE file. |
47 ` | 47 ` |
48 | 48 |
49 func (a *app) parseArgs(fs *flag.FlagSet, args []string) error { | 49 func (a *app) parseArgs(fs *flag.FlagSet, args []string) error { |
50 fs.SetOutput(a.out) | 50 fs.SetOutput(a.out) |
51 fs.Usage = func() { | 51 fs.Usage = func() { |
52 fmt.Fprintf(a.out, help, args[0], args[0]) | 52 fmt.Fprintf(a.out, help, args[0], args[0]) |
53 fs.PrintDefaults() | 53 fs.PrintDefaults() |
54 } | 54 } |
55 | 55 |
56 fs.Var(&a.typeNames, "type", | 56 fs.Var(&a.typeNames, "type", |
57 "A generated proto.Message type to generate stubs for (required, repeatable)") | 57 "A generated proto.Message type to generate stubs for (required, repeatable)") |
58 fs.StringVar(&a.outFile, "out", "proto_gae.gen.go", | 58 fs.StringVar(&a.outFile, "out", "proto_gae.gen.go", |
59 "The name of the output file") | 59 "The name of the output file") |
60 fs.StringVar(&a.header, "header", copyright, "Header text to put at the top of "+ | 60 fs.StringVar(&a.header, "header", copyright, "Header text to put at the top of "+ |
61 » » "the generated file. Defaults to the Chromium Authors copyright. ") | 61 » » "the generated file. Defaults to the LUCI Authors copyright.") |
62 | 62 |
63 if err := fs.Parse(args[1:]); err != nil { | 63 if err := fs.Parse(args[1:]); err != nil { |
64 return err | 64 return err |
65 } | 65 } |
66 fail := errors.MultiError(nil) | 66 fail := errors.MultiError(nil) |
67 if a.typeNames.Data == nil || a.typeNames.Data.Len() == 0 { | 67 if a.typeNames.Data == nil || a.typeNames.Data.Len() == 0 { |
68 fail = append(fail, errors.New("must specify one or more -type") ) | 68 fail = append(fail, errors.New("must specify one or more -type") ) |
69 } | 69 } |
70 if !strings.HasSuffix(a.outFile, ".go") { | 70 if !strings.HasSuffix(a.outFile, ".go") { |
71 fail = append(fail, errors.New("-output must end with '.go'")) | 71 fail = append(fail, errors.New("-output must end with '.go'")) |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 if err := buf.Flush(); err != nil { | 161 if err := buf.Flush(); err != nil { |
162 fmt.Fprintf(a.out, "error while writing: %s", err) | 162 fmt.Fprintf(a.out, "error while writing: %s", err) |
163 closeFn(true) | 163 closeFn(true) |
164 os.Exit(4) | 164 os.Exit(4) |
165 } | 165 } |
166 } | 166 } |
167 | 167 |
168 func main() { | 168 func main() { |
169 (&app{out: os.Stderr, packageName: os.Getenv("GOPACKAGE")}).main() | 169 (&app{out: os.Stderr, packageName: os.Getenv("GOPACKAGE")}).main() |
170 } | 170 } |
OLD | NEW |