forked from uber/prototool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flags.go
153 lines (125 loc) · 6.23 KB
/
flags.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// Copyright (c) 2018 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package cmd
import (
"github.com/spf13/pflag"
)
type flags struct {
address string
cachePath string
callTimeout string
connectTimeout string
data string
debug bool
diffMode bool
dirMode bool
disableFormat bool
disableLint bool
dryRun bool
harbormaster bool
headers []string
keepaliveTime string
listAllLinters bool
listLinters bool
lintMode bool
method string
overwrite bool
pkg string
printFields string
protocURL string
stdin bool
uncomment bool
noRewrite bool
}
func (f *flags) bindAddress(flagSet *pflag.FlagSet) {
flagSet.StringVar(&f.address, "address", "", "The GRPC endpoint to connect to. This is required.")
}
func (f *flags) bindCachePath(flagSet *pflag.FlagSet) {
flagSet.StringVar(&f.cachePath, "cache-path", "", "The path to use for the cache, otherwise uses the default behavior.")
}
func (f *flags) bindCallTimeout(flagSet *pflag.FlagSet) {
flagSet.StringVar(&f.callTimeout, "call-timeout", "60s", "The maximum time to for all calls to be completed.")
}
func (f *flags) bindConnectTimeout(flagSet *pflag.FlagSet) {
flagSet.StringVar(&f.connectTimeout, "connect-timeout", "10s", "The maximum time to wait for the connection to be established.")
}
func (f *flags) bindData(flagSet *pflag.FlagSet) {
flagSet.StringVar(&f.data, "data", "", "The GRPC request data in JSON format. Either this or --stdin is required.")
}
func (f *flags) bindDebug(flagSet *pflag.FlagSet) {
flagSet.BoolVar(&f.debug, "debug", false, "Run in debug mode, which will print out debug logging.")
}
func (f *flags) bindDiffMode(flagSet *pflag.FlagSet) {
flagSet.BoolVarP(&f.diffMode, "diff", "d", false, "Write a diff instead of writing the formatted file to stdout.")
}
func (f *flags) bindDirMode(flagSet *pflag.FlagSet) {
flagSet.BoolVar(&f.dirMode, "dir-mode", false, "Run as if the directory the file was given, but only print the errors from the file. Useful for integration with editors.")
}
func (f *flags) bindDisableFormat(flagSet *pflag.FlagSet) {
flagSet.BoolVar(&f.disableFormat, "disable-format", false, "Do not run formatting.")
}
func (f *flags) bindDisableLint(flagSet *pflag.FlagSet) {
flagSet.BoolVar(&f.disableLint, "disable-lint", false, "Do not run linting.")
}
func (f *flags) bindDryRun(flagSet *pflag.FlagSet) {
flagSet.BoolVar(&f.dryRun, "dry-run", false, "Print the protoc commands that would have been run without actually running them.")
}
func (f *flags) bindHarbormaster(flagSet *pflag.FlagSet) {
flagSet.BoolVar(&f.harbormaster, "harbormaster", false, "Print failures in JSON compatible with the Harbormaster API.")
}
func (f *flags) bindHeaders(flagSet *pflag.FlagSet) {
flagSet.StringSliceVarP(&f.headers, "header", "H", []string{}, "Additional request headers in 'name:value' format.")
}
func (f *flags) bindKeepaliveTime(flagSet *pflag.FlagSet) {
flagSet.StringVar(&f.keepaliveTime, "keepalive-time", "", "The maximum idle time after which a keepalive probe is sent.")
}
func (f *flags) bindLintMode(flagSet *pflag.FlagSet) {
flagSet.BoolVarP(&f.lintMode, "lint", "l", false, "Write a lint error saying that the file is not formatted instead of writing the formatted file to stdout.")
}
func (f *flags) bindListAllLinters(flagSet *pflag.FlagSet) {
flagSet.BoolVar(&f.listAllLinters, "list-all-linters", false, "List all available linters instead of running lint.")
}
func (f *flags) bindListLinters(flagSet *pflag.FlagSet) {
flagSet.BoolVar(&f.listLinters, "list-linters", false, "List the configured linters instead of running lint.")
}
func (f *flags) bindMethod(flagSet *pflag.FlagSet) {
flagSet.StringVar(&f.method, "method", "", "The GRPC method to call in the form package.Service/Method. This is required.")
}
func (f *flags) bindOverwrite(flagSet *pflag.FlagSet) {
flagSet.BoolVarP(&f.overwrite, "overwrite", "w", false, "Overwrite the existing file instead of writing the formatted file to stdout.")
}
func (f *flags) bindPackage(flagSet *pflag.FlagSet) {
flagSet.StringVar(&f.pkg, "package", "", "The Protobuf package to use in the created file.")
}
func (f *flags) bindPrintFields(flagSet *pflag.FlagSet) {
flagSet.StringVar(&f.printFields, "print-fields", "filename:line:column:message", "The colon-separated fields to print out on error.")
}
func (f *flags) bindProtocURL(flagSet *pflag.FlagSet) {
flagSet.StringVar(&f.protocURL, "protoc-url", "", "The url to use to download the protoc zip file, otherwise uses GitHub Releases. Setting this option will ignore the config protoc_version setting.")
}
func (f *flags) bindStdin(flagSet *pflag.FlagSet) {
flagSet.BoolVar(&f.stdin, "stdin", false, "Read the GRPC request data from stdin in JSON format. Either this or --data is required.")
}
func (f *flags) bindUncomment(flagSet *pflag.FlagSet) {
flagSet.BoolVar(&f.uncomment, "uncomment", false, "Uncomment the example config settings.")
}
func (f *flags) bindNoRewrite(flagSet *pflag.FlagSet) {
flagSet.BoolVar(&f.noRewrite, "no-rewrite", false, "Do not rewrite the file options go_package, java_multiple_files, java_outer_classname, and java_package to match the package per the guidelines of the style guide.")
}