-
Notifications
You must be signed in to change notification settings - Fork 245
/
buf.go
337 lines (331 loc) · 15.4 KB
/
buf.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
// Copyright 2020-2021 Buf Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package buf
import (
"context"
"time"
"github.com/bufbuild/buf/private/buf/bufcli"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/alpha/registry/token/tokencreate"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/alpha/registry/token/tokendelete"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/alpha/registry/token/tokenget"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/alpha/registry/token/tokenlist"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/commit/commitget"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/commit/commitlist"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/organization/organizationcreate"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/organization/organizationdelete"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/organization/organizationget"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/plugin/plugincreate"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/plugin/plugindelete"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/plugin/pluginlist"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/plugin/pluginversion/pluginversionlist"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/repository/repositorycreate"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/repository/repositorydelete"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/repository/repositorydeprecate"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/repository/repositoryget"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/repository/repositorylist"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/repository/repositoryundeprecate"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/tag/tagcreate"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/tag/taglist"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/template/templatecreate"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/template/templatedelete"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/template/templatelist"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/template/templateversion/templateversioncreate"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/template/templateversion/templateversionlist"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/breaking"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/build"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/config/configinit"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/config/configlsbreakingrules"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/config/configlslintrules"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/config/configmigratev1beta1"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/export"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/generate"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/lint"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/lsfiles"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/mod/modclearcache"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/mod/modprune"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/mod/modupdate"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/protoc"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/push"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/registry/registrylogin"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/registry/registrylogout"
"github.com/bufbuild/buf/private/pkg/app/appcmd"
"github.com/bufbuild/buf/private/pkg/app/appflag"
)
const (
betaConfigDeprecationMessage = `"buf beta config ..." has been moved to "buf config ...".` + bufcli.DeprecationMessageSuffix
betaConfigInitDeprecationMessage = `"buf beta config init" has been moved to "buf config init".` + bufcli.DeprecationMessageSuffix
betaImageConvertDeprecationMessage = `"buf beta image convert" has been moved to "buf build".` + bufcli.DeprecationMessageSuffix
betaModClearCacheDeprecationMessage = `"buf beta mod clear-cache" has been moved to "buf mod clear-cache".` + bufcli.DeprecationMessageSuffix
betaModDeprecationMessage = `"buf beta mod ..." has been moved to "buf mod ...".` + bufcli.DeprecationMessageSuffix
betaModExportDeprecationMessage = `"buf beta mod export" has been moved to "buf export".` + bufcli.DeprecationMessageSuffix
betaModInitDeprecationMessage = `"buf beta mod init" has been moved to "buf config init".` + bufcli.DeprecationMessageSuffix
betaModUpdateDeprecationMessage = `"buf beta mod update" has been moved to "buf mod update".` + bufcli.DeprecationMessageSuffix
betaPushDeprecationMessage = `"buf beta push" has been moved to "buf mod push".` + bufcli.DeprecationMessageSuffix
checkBreakingDeprecationMessage = `"buf check breaking" has been moved to "buf breaking".` + bufcli.DeprecationMessageSuffix
checkDeprecationMessage = `"buf check" sub-commands are now all implemented with the top-level "buf lint" and "buf breaking" commands.` + bufcli.DeprecationMessageSuffix
checkLintDeprecationMessage = `"buf check lint" has been moved to "buf lint".` + bufcli.DeprecationMessageSuffix
checkLsBreakingCheckersDeprecationMessage = `"buf check ls-breaking-checkers" has been moved to "buf config ls-breaking-rules".` + bufcli.DeprecationMessageSuffix
checkLsLintCheckersDeprecationMessage = `"buf check ls-lint-checkers" has been moved to "buf config ls-lint-rules".` + bufcli.DeprecationMessageSuffix
experimentalDeprecationMessage = `"buf experimental" sub-commands have moved to "buf beta".` + bufcli.DeprecationMessageSuffix
experimentalImageConvertDeprecationMessage = `"buf experimental image convert" has been moved to "buf build".` + bufcli.DeprecationMessageSuffix
imageBuildDeprecationMessage = `"buf image build" has been moved to "buf build".` + bufcli.DeprecationMessageSuffix
imageDeprecationMessage = `"buf image" sub-commands are now all implemented under the top-level "buf build" command.` + bufcli.DeprecationMessageSuffix
loginDeprecationMessage = `"buf login" has been moved to "buf registry login".` + bufcli.DeprecationMessageSuffix
logoutDeprecationMessage = `"buf logout" has been moved to "buf registry logout".` + bufcli.DeprecationMessageSuffix
modInitDeprecationMessage = `"buf mod init" has been moved to "buf config init".` + bufcli.DeprecationMessageSuffix
pushDeprecationMessage = `"buf push" has been moved to "buf mod push".` + bufcli.DeprecationMessageSuffix
)
// Main is the entrypoint to the buf CLI.
func Main(name string) {
appcmd.Main(context.Background(), NewRootCommand(name))
}
// NewRootCommand returns a new root command.
//
// This is public for use in testing.
func NewRootCommand(name string) *appcmd.Command {
builder := appflag.NewBuilder(
name,
appflag.BuilderWithTimeout(120*time.Second),
appflag.BuilderWithTracing(),
)
globalFlags := bufcli.NewGlobalFlags()
return &appcmd.Command{
Use: name,
Version: bufcli.Version,
BindPersistentFlags: appcmd.BindMultiple(builder.BindRoot, globalFlags.BindRoot),
SubCommands: []*appcmd.Command{
build.NewCommand("build", builder),
export.NewCommand("export", builder),
lint.NewCommand("lint", builder),
breaking.NewCommand("breaking", builder),
generate.NewCommand("generate", builder),
protoc.NewCommand("protoc", builder),
lsfiles.NewCommand("ls-files", builder),
push.NewCommand("push", builder),
{
Use: "mod",
Short: "Configure and update buf modules.",
SubCommands: []*appcmd.Command{
appcmd.NewDeletedCommand("init", modInitDeprecationMessage),
modprune.NewCommand("prune", builder),
modupdate.NewCommand("update", builder),
modclearcache.NewCommand("clear-cache", builder, "cc"),
},
},
{
Use: "config",
Short: "Interact with the configuration of Buf.",
SubCommands: []*appcmd.Command{
configinit.NewCommand("init", builder),
configlslintrules.NewCommand("ls-lint-rules", builder),
configlsbreakingrules.NewCommand("ls-breaking-rules", builder),
configmigratev1beta1.NewCommand("migrate-v1beta1", builder),
},
},
{
Use: "registry",
Short: "Interact with the Buf Schema Registry.",
SubCommands: []*appcmd.Command{
registrylogin.NewCommand("login", builder),
registrylogout.NewCommand("logout", builder),
},
},
{
Use: "beta",
Short: "Beta commands. Unstable and will likely change.",
SubCommands: []*appcmd.Command{
{
Use: "registry",
Short: "Interact with the Buf Schema Registry.",
SubCommands: []*appcmd.Command{
{
Use: "organization",
Short: "Organization commands.",
SubCommands: []*appcmd.Command{
organizationcreate.NewCommand("create", builder),
organizationget.NewCommand("get", builder),
organizationdelete.NewCommand("delete", builder),
},
},
{
Use: "repository",
Short: "Repository commands.",
SubCommands: []*appcmd.Command{
repositorycreate.NewCommand("create", builder),
repositoryget.NewCommand("get", builder),
repositorylist.NewCommand("list", builder),
repositorydelete.NewCommand("delete", builder),
repositorydeprecate.NewCommand("deprecate", builder),
repositoryundeprecate.NewCommand("undeprecate", builder),
},
},
//{
// Use: "branch",
// Short: "Repository branch commands.",
// SubCommands: []*appcmd.Command{
// branchcreate.NewCommand("create", builder),
// branchlist.NewCommand("list", builder),
// },
//},
{
Use: "tag",
Short: "Repository tag commands.",
SubCommands: []*appcmd.Command{
tagcreate.NewCommand("create", builder),
taglist.NewCommand("list", builder),
},
},
{
Use: "commit",
Short: "Repository commit commands.",
SubCommands: []*appcmd.Command{
commitget.NewCommand("get", builder),
commitlist.NewCommand("list", builder),
},
},
{
Use: "plugin",
Short: "Plugin commands.",
SubCommands: []*appcmd.Command{
plugincreate.NewCommand("create", builder),
pluginlist.NewCommand("list", builder),
plugindelete.NewCommand("delete", builder),
{
Use: "version",
Short: "Plugin version commands.",
SubCommands: []*appcmd.Command{
pluginversionlist.NewCommand("list", builder),
},
},
},
},
{
Use: "template",
Short: "Template commands.",
SubCommands: []*appcmd.Command{
templatecreate.NewCommand("create", builder),
templatelist.NewCommand("list", builder),
templatedelete.NewCommand("delete", builder),
{
Use: "version",
Short: "Template version commands.",
SubCommands: []*appcmd.Command{
templateversioncreate.NewCommand("create", builder),
templateversionlist.NewCommand("list", builder),
},
},
},
},
},
},
{
Use: "config",
Short: "Interact with the configuration of Buf.",
Deprecated: betaConfigDeprecationMessage,
Hidden: true,
SubCommands: []*appcmd.Command{
appcmd.NewDeletedCommand("init", betaConfigInitDeprecationMessage),
},
},
{
Use: "image",
Short: "Work with Images and FileDescriptorSets.",
Deprecated: imageDeprecationMessage,
Hidden: true,
SubCommands: []*appcmd.Command{
appcmd.NewDeletedCommand("convert", betaImageConvertDeprecationMessage),
},
},
{
Use: "mod",
Short: "Configure and update buf modules.",
Deprecated: betaModDeprecationMessage,
Hidden: true,
SubCommands: []*appcmd.Command{
appcmd.NewDeletedCommand("init", betaModInitDeprecationMessage),
appcmd.NewDeletedCommand("update", betaModUpdateDeprecationMessage),
appcmd.NewDeletedCommand("export", betaModExportDeprecationMessage),
appcmd.NewDeletedCommand("clear-cache", betaModClearCacheDeprecationMessage, "cc"),
},
},
appcmd.NewDeletedCommand("push", betaPushDeprecationMessage),
},
},
{
Use: "alpha",
Short: "Alpha commands. These are so early in development that they should not be used except in development.",
Hidden: true,
SubCommands: []*appcmd.Command{
{
Use: "registry",
Short: "Interact with the Buf Schema Registry.",
SubCommands: []*appcmd.Command{
{
Use: "token",
Short: "Token commands.",
SubCommands: []*appcmd.Command{
tokencreate.NewCommand("create", builder),
tokenget.NewCommand("get", builder),
tokenlist.NewCommand("list", builder),
tokendelete.NewCommand("delete", builder),
},
},
},
},
},
},
appcmd.NewDeletedCommand("login", loginDeprecationMessage),
appcmd.NewDeletedCommand("logout", logoutDeprecationMessage),
appcmd.NewDeletedCommand("push", pushDeprecationMessage),
{
Use: "image",
Short: "Work with Images and FileDescriptorSets.",
Deprecated: imageDeprecationMessage,
Hidden: true,
SubCommands: []*appcmd.Command{
appcmd.NewDeletedCommand("build", imageBuildDeprecationMessage),
},
},
{
Use: "check",
Short: "Run linting or breaking change detection.",
Deprecated: checkDeprecationMessage,
Hidden: true,
SubCommands: []*appcmd.Command{
appcmd.NewDeletedCommand("lint", checkLintDeprecationMessage),
appcmd.NewDeletedCommand("breaking", checkBreakingDeprecationMessage),
appcmd.NewDeletedCommand("ls-lint-checkers", checkLsLintCheckersDeprecationMessage),
appcmd.NewDeletedCommand("ls-breaking-checkers", checkLsBreakingCheckersDeprecationMessage),
},
},
{
Use: "experimental",
Short: "Experimental commands. Unstable and will likely change.",
Deprecated: experimentalDeprecationMessage,
Hidden: true,
SubCommands: []*appcmd.Command{
{
Use: "image",
Short: "Work with Images and FileDescriptorSets.",
Deprecated: imageDeprecationMessage,
Hidden: true,
SubCommands: []*appcmd.Command{
appcmd.NewDeletedCommand("convert", experimentalImageConvertDeprecationMessage),
},
},
},
},
},
}
}