Skip to content

Commit 2ff1b33

Browse files
oliversun9bufdev
andauthored
Promote beta registry organization, module, label and commit commands (#3170)
This PR moves `[module, organization, label, commit]` commands out of beta. Here are pruned outputs of `--help-tree` before and after. Before ``` buf registry --help-tree registry Manage assets on the Buf Schema Registry archive Archive one or more labels for the given input commit Manage a repository's commits get Get commit details list List repository commits label Manage a repository's labels create Create a label for a specified commit get Get label details list List repository labels organization Manage organizations create Create a new BSR organization delete Delete a BSR organization get Get a BSR organization repository Manage repositories create Create a BSR repository delete Delete a BSR repository deprecate Deprecate a BSR repository get Get a BSR repository list List BSR repositories undeprecate Undeprecate a BSR repository update Update BSR repository settings unarchive Unarchive one or more labels for the given input ``` After ``` buf registry --help-tree registry Manage assets on the Buf Schema Registry commit Manage a module's commits add-label Add labels to a commit info Get commit information list List modules commits resolve Resolve commit from a reference label Manage a module's labels archive Archive a module label info Show label information list List module labels unarchive Unarchive a module label module Manage BSR modules create Create a BSR module delete Delete a BSR module deprecate Deprecate a BSR module info Get a BSR module undeprecate Undeprecate a BSR module update Update BSR module settings organization Manage organizations create Create a new BSR organization delete Delete a BSR organization info Show information about a BSR organization update Update a BSR organization ``` Fixes #1431 --------- Co-authored-by: bufdev <[email protected]>
1 parent 72d6cc3 commit 2ff1b33

File tree

62 files changed

+1444
-1142
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1444
-1142
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
- Fix git input handling of annotated tags.
99
- Update `buf registry login` to complete the login flow in the browser by default. This allows
1010
users to login with their browser and have the token automatically provided to the CLI.
11+
- Add `buf registry organization {create, delete, info, update}` commands to manage BSR
12+
organizations. Remove `buf beta registry organization` commands.
13+
- Add `buf registry module {create, delete, deprecate, info, undeprecate, update}` commands to
14+
manage BSR modules. Remove `buf beta registry repository` commands.
15+
- Add `buf registry label {archive, info, list, unarchive}` commands to manage BSR module labels.
16+
Remove `buf beta registry label` commands and `buf beta registy {archive, unarchive}`.
17+
- Add `buf registry commit {add-label, info, list, resolve}` to manage BSR module commits. Remove
18+
`buf beta registry commit` commands.
1119

1220
## [v1.35.1] - 2024-07-24
1321

private/buf/bufcli/errors.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ func NewOrganizationNameAlreadyExistsError(name string) error {
4242
return fmt.Errorf("an organization named %q already exists", name)
4343
}
4444

45-
// NewRepositoryNameAlreadyExistsError informs the user that a repository
45+
// NewModuleNameAlreadyExistsError informs the user that a module
4646
// with that name already exists.
47-
func NewRepositoryNameAlreadyExistsError(name string) error {
48-
return fmt.Errorf("a repository named %q already exists", name)
47+
func NewModuleNameAlreadyExistsError(name string) error {
48+
return fmt.Errorf("a module named %q already exists", name)
4949
}
5050

5151
// NewLabelNameAlreadyExistsError informs the user that a label
@@ -57,7 +57,7 @@ func NewLabelNameAlreadyExistsError(name string) error {
5757
// NewOrganizationNotFoundError informs the user that an organization with
5858
// that name does not exist.
5959
func NewOrganizationNotFoundError(name string) error {
60-
return fmt.Errorf(`an organization named %q does not exist, use "buf beta registry organization create" to create one`, name)
60+
return fmt.Errorf(`an organization named %q does not exist, use "buf registry organization create" to create one`, name)
6161
}
6262

6363
// NewOrganizationOrUserNotFoundError informs the user that an organization or user with
@@ -66,10 +66,10 @@ func NewOrganizationOrUserNotFoundError(name string) error {
6666
return fmt.Errorf(`an organization or user named %q does not exist`, name)
6767
}
6868

69-
// NewRepositoryNotFoundError informs the user that a repository with
69+
// NewModuleNotFoundError informs the user that a module with
7070
// that name does not exist.
71-
func NewRepositoryNotFoundError(name string) error {
72-
return fmt.Errorf(`a repository named %q does not exist, use "buf beta registry repository create" to create one`, name)
71+
func NewModuleNotFoundError(name string) error {
72+
return fmt.Errorf(`a module named %q does not exist, use "buf registry module create" to create one`, name)
7373
}
7474

7575
// NewModuleRefNotFoundError informs the user that a ModuleRef does not exist.

private/buf/bufcli/flag_args_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2020-2024 Buf Technologies, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package bufcli
16+
17+
import (
18+
"testing"
19+
20+
"github.com/spf13/pflag"
21+
"github.com/stretchr/testify/require"
22+
)
23+
24+
func TestStringPointerFlagSet(t *testing.T) {
25+
t.Parallel()
26+
expected := "foo"
27+
testParseStringPointer(t, "test-flag-name", &expected, "--test-flag-name", "foo")
28+
}
29+
30+
func TestStringPointerFlagSetEmpty(t *testing.T) {
31+
t.Parallel()
32+
expected := ""
33+
testParseStringPointer(t, "test-flag-name", &expected, "--test-flag-name", "")
34+
}
35+
36+
func TestStringPointerFlagNotSet(t *testing.T) {
37+
t.Parallel()
38+
testParseStringPointer(t, "test-flag-name", nil)
39+
}
40+
41+
func testParseStringPointer(t *testing.T, flagName string, expectedResult *string, args ...string) {
42+
var stringPointer *string
43+
flagSet := pflag.NewFlagSet("test flag set", pflag.ContinueOnError)
44+
BindStringPointer(flagSet, flagName, &stringPointer, "test usage")
45+
err := flagSet.Parse(args)
46+
require.NoError(t, err)
47+
require.Equal(t, expectedResult, stringPointer)
48+
}

private/buf/bufcli/flags_args.go

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import (
2828
)
2929

3030
const (
31+
DefaultArchiveStatus = unarchivedArchiveStatus
32+
3133
inputHashtagFlagName = "__hashtag__"
3234
inputHashtagFlagShortName = "#"
3335

@@ -142,12 +144,16 @@ By default, symlinks are followed in this CLI, but never followed on the Buf Sch
142144
}
143145

144146
// BindVisibility binds the visibility flag.
145-
func BindVisibility(flagSet *pflag.FlagSet, addr *string, flagName string) {
147+
func BindVisibility(flagSet *pflag.FlagSet, addr *string, flagName string, emptyDefault bool) {
148+
defaultVisibility := privateVisibility
149+
if emptyDefault {
150+
defaultVisibility = ""
151+
}
146152
flagSet.StringVar(
147153
addr,
148154
flagName,
149-
"",
150-
fmt.Sprintf(`The repository's visibility setting. Must be one of %s`, stringutil.SliceToString(allVisibiltyStrings)),
155+
defaultVisibility,
156+
fmt.Sprintf(`The module's visibility setting. Must be one of %s`, stringutil.SliceToString(allVisibiltyStrings)),
151157
)
152158
}
153159

@@ -158,7 +164,7 @@ func BindCreateVisibility(flagSet *pflag.FlagSet, addr *string, flagName string,
158164
addr,
159165
flagName,
160166
privateVisibility,
161-
fmt.Sprintf(`The repository's visibility setting, if created. Can only be set with --%s. Must be one of %s`, createFlagName, stringutil.SliceToString(allVisibiltyStrings)),
167+
fmt.Sprintf(`The module's visibility setting, if created. Can only be set with --%s. Must be one of %s`, createFlagName, stringutil.SliceToString(allVisibiltyStrings)),
162168
)
163169
}
164170

@@ -168,11 +174,48 @@ func BindArchiveStatus(flagSet *pflag.FlagSet, addr *string, flagName string) {
168174
flagSet.StringVar(
169175
addr,
170176
flagName,
171-
unarchivedArchiveStatus,
177+
DefaultArchiveStatus,
172178
fmt.Sprintf(`The archive status of the labels listed. Must be one of %s`, stringutil.SliceToString(allArchiveStatusStrings)),
173179
)
174180
}
175181

182+
// Binds a string pointer flag, which indicates flag presence, i.e. `--flag ""` is not the same as not passing the flag.
183+
//
184+
// This is useful for buf registry organization/module update, where we only modify the fields specified.
185+
//
186+
// Value must not be nil.
187+
func BindStringPointer(flagSet *pflag.FlagSet, name string, value **string, usage string) {
188+
flagSet.Var(
189+
&stringPointerValue{
190+
valuePointer: value,
191+
},
192+
name,
193+
usage,
194+
)
195+
}
196+
197+
// Implements pflag.Value.
198+
type stringPointerValue struct {
199+
// This must not be nil at construction time.
200+
valuePointer **string
201+
}
202+
203+
func (b *stringPointerValue) Type() string {
204+
return "string"
205+
}
206+
207+
func (b *stringPointerValue) String() string {
208+
if *b.valuePointer == nil {
209+
return ""
210+
}
211+
return **b.valuePointer
212+
}
213+
214+
func (b *stringPointerValue) Set(value string) error {
215+
*b.valuePointer = &value
216+
return nil
217+
}
218+
176219
// GetInputLong gets the long command description for an input-based command.
177220
func GetInputLong(inputArgDescription string) string {
178221
return fmt.Sprintf(
@@ -245,18 +288,6 @@ func GetInputValue(
245288
return defaultValue, nil
246289
}
247290

248-
// VisibilityFlagToVisibility parses the given string as a modulev1.ModuleVisibility
249-
func VisibilityFlagToVisibility(visibility string) (modulev1.ModuleVisibility, error) {
250-
switch visibility {
251-
case publicVisibility:
252-
return modulev1.ModuleVisibility_MODULE_VISIBILITY_PUBLIC, nil
253-
case privateVisibility:
254-
return modulev1.ModuleVisibility_MODULE_VISIBILITY_PRIVATE, nil
255-
default:
256-
return 0, fmt.Errorf("invalid visibility: %s, expected one of %s", visibility, stringutil.SliceToString(allVisibiltyStrings))
257-
}
258-
}
259-
260291
// VisibilityFlagToVisibilityAllowUnspecified parses the given string as a modulev1.ModuleVisibility
261292
// where an empty string will be parsed as unspecified
262293
func VisibilityFlagToVisibilityAllowUnspecified(visibility string) (modulev1.ModuleVisibility, error) {

private/buf/bufcli/module_owner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
// ModuleOwner represents a module owner, consisting of a registry and owner.
2626
//
2727
// This concept used to live in bufmodule but it doesn't really make sense there, as it isn't
28-
// use anywhere else. We only use this in buf beta registry organization commands at the moment.
28+
// use anywhere else. We only use this in buf registry organization commands at the moment.
2929
type ModuleOwner interface {
3030
// String returns "registry/owner".
3131
fmt.Stringer

private/buf/bufprint/bufprint.go

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
modulev1 "buf.build/gen/go/bufbuild/registry/protocolbuffers/go/buf/registry/module/v1"
2424
ownerv1 "buf.build/gen/go/bufbuild/registry/protocolbuffers/go/buf/registry/owner/v1"
25+
"github.com/bufbuild/buf/private/bufpkg/bufmodule"
2526
registryv1alpha1 "github.com/bufbuild/buf/private/gen/proto/go/buf/alpha/registry/v1alpha1"
2627
"github.com/bufbuild/buf/private/pkg/connectclient"
2728
"github.com/bufbuild/buf/private/pkg/protoencoding"
@@ -85,50 +86,53 @@ func NewCuratedPluginPrinter(writer io.Writer) CuratedPluginPrinter {
8586

8687
// OrganizationPrinter is an organization printer.
8788
type OrganizationPrinter interface {
88-
PrintOrganization(ctx context.Context, format Format, organization *ownerv1.Organization) error
89+
PrintOrganizationInfo(ctx context.Context, format Format, organization *ownerv1.Organization) error
8990
}
9091

9192
// NewOrganizationPrinter returns a new OrganizationPrinter.
9293
func NewOrganizationPrinter(address string, writer io.Writer) OrganizationPrinter {
9394
return newOrganizationPrinter(address, writer)
9495
}
9596

96-
// RepositoryPrinter is a repository printer.
97-
type RepositoryPrinter interface {
98-
PrintRepository(ctx context.Context, format Format, repository *modulev1.Module) error
99-
PrintRepositories(ctx context.Context, format Format, nextPageToken string, repositories ...*modulev1.Module) error
97+
// ModulePrinter is a module printer.
98+
type ModulePrinter interface {
99+
PrintModuleInfo(ctx context.Context, format Format, repository *modulev1.Module) error
100100
}
101101

102-
// NewRepositoryPrinter returns a new RepositoryPrinter.
103-
func NewRepositoryPrinter(
102+
// NewModulePrinter returns a new ModulePrinter.
103+
func NewModulePrinter(
104104
clientConfig *connectclient.Config,
105105
address string,
106106
writer io.Writer,
107-
) RepositoryPrinter {
108-
return newRepositoryPrinter(clientConfig, address, writer)
107+
) ModulePrinter {
108+
return newModulePrinter(clientConfig, address, writer)
109109
}
110110

111-
// RepositoryLabelPrinter is a repository label printer.
112-
// TODO: perhaps rename this to LabelPrinter along with other printers
113-
type RepositoryLabelPrinter interface {
114-
PrintRepositoryLabel(ctx context.Context, format Format, label *modulev1.Label) error
115-
PrintRepositoryLabels(ctx context.Context, format Format, nextPageToken string, labels ...*modulev1.Label) error
111+
// LabelPrinter is a repository label printer.
112+
type LabelPrinter interface {
113+
// PrintLabels prints each label on a new line.
114+
PrintLabels(ctx context.Context, format Format, label ...*modulev1.Label) error
115+
// PrintLabels prints information about a label.
116+
PrintLabelInfo(ctx context.Context, format Format, label *modulev1.Label) error
117+
// PrintLabelPage prints a page of labels.
118+
PrintLabelPage(ctx context.Context, format Format, nextPageCommand, nextPageToken string, labels []*modulev1.Label) error
116119
}
117120

118-
// NewRepositoryLabelPrinter returns a new RepositoryLabelPrinter.
119-
func NewRepositoryLabelPrinter(writer io.Writer) RepositoryLabelPrinter {
120-
return newRepositoryLabelPrinter(writer)
121+
// NewLabelPrinter returns a new RepositoryLabelPrinter.
122+
func NewLabelPrinter(writer io.Writer, moduleFullName bufmodule.ModuleFullName) LabelPrinter {
123+
return newLabelPrinter(writer, moduleFullName)
121124
}
122125

123-
// RepositoryCommitPrinter is a repository commit printer.
124-
type RepositoryCommitPrinter interface {
125-
PrintRepositoryCommit(ctx context.Context, format Format, repositoryCommit *modulev1.Commit) error
126-
PrintRepositoryCommits(ctx context.Context, format Format, nextPageToken string, repositoryCommits ...*modulev1.Commit) error
126+
// CommitPrinter is a commit printer.
127+
type CommitPrinter interface {
128+
PrintCommitInfo(ctx context.Context, format Format, commit *modulev1.Commit) error
129+
PrintCommits(ctx context.Context, format Format, commits ...*modulev1.Commit) error
130+
PrintCommitPage(ctx context.Context, format Format, nextPageCommand, nextPageToken string, commits []*modulev1.Commit) error
127131
}
128132

129-
// NewRepositoryCommitPrinter returns a new RepositoryCommitPrinter.
130-
func NewRepositoryCommitPrinter(writer io.Writer) RepositoryCommitPrinter {
131-
return newRepositoryCommitPrinter(writer)
133+
// NewCommitPrinter returns a new RepositoryCommitPrinter.
134+
func NewCommitPrinter(writer io.Writer, moduleFullName bufmodule.ModuleFullName) CommitPrinter {
135+
return newCommitPrinter(writer, moduleFullName)
132136
}
133137

134138
// TokenPrinter is a token printer.

0 commit comments

Comments
 (0)