Skip to content

Commit e75e108

Browse files
committed
v0.1.7 inline org create and misc fixes
1 parent 3d6f325 commit e75e108

38 files changed

+893
-627
lines changed

api/api.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package api
22

3-
//go:generate go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --package=api -generate=types -o ./openapi.gen.go ../../config/openapi.yml
3+
//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --package=api -generate=types -o ./openapi.gen.go ../../config/openapi.yml
44

55
import (
66
"bytes"
@@ -204,9 +204,21 @@ func (s *Session) CreateEAB(ctx context.Context, chainSlug, orgSlug, realmSlug,
204204
return &eabOutput, nil
205205
}
206206

207-
func (s *Session) CreateService(ctx context.Context, orgSlug, serviceSlug, serverType string, localhostPort *int) (*Service, error) {
207+
func (s *Session) CreateOrg(ctx context.Context, orgName string) (*Organization, error) {
208+
orgInput := CreateOrgJSONRequestBody{
209+
Name: orgName,
210+
}
211+
212+
var orgOutput Organization
213+
if err := s.post(ctx, "/orgs", orgInput, &orgOutput); err != nil {
214+
return nil, err
215+
}
216+
return &orgOutput, nil
217+
}
218+
219+
func (s *Session) CreateService(ctx context.Context, orgSlug, serviceName, serverType string, localhostPort *int) (*Service, error) {
208220
serviceInput := CreateServiceJSONRequestBody{
209-
Name: serviceSlug,
221+
Name: serviceName,
210222
ServerType: serverType,
211223
LocalhostPort: localhostPort,
212224
}

api/openapi.gen.go

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/tools.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
package api
55

66
import (
7-
_ "github.com/deepmap/oapi-codegen/cmd/oapi-codegen"
7+
_ "github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen"
88
)

component/models/selectors.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package models
22

33
import (
44
"fmt"
5-
"reflect"
65
"strings"
76

87
"github.com/charmbracelet/bubbles/list"
@@ -144,7 +143,8 @@ func (m *Selector[T]) View() string {
144143
return b.String()
145144
}
146145

147-
if reflect.ValueOf(m.chosen.Value).IsZero() {
146+
var zeroT T
147+
if m.chosen.Value == zeroT {
148148
fmt.Fprintln(&b, ui.StepDone(
149149
fmt.Sprintf("Selected %s.", ui.Emphasize(m.chosen.String)),
150150
))

component/selector_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,69 @@ func TestSelector(t *testing.T) {
7878
uitest.TestGolden(t, drv.Golden())
7979
})
8080

81+
t.Run("orgs solo creatable", func(t *testing.T) {
82+
if srv.IsProxy() {
83+
t.Skip("selector tests unsupported in proxy mode")
84+
}
85+
86+
cfg.Test.Prefer = map[string]cli.ConfigTestPrefer{
87+
"/v0/orgs": {
88+
Example: "solo",
89+
},
90+
}
91+
ctx = cli.ContextWithConfig(ctx, cfg)
92+
93+
drv, tm := uitest.TestTUI(ctx, t)
94+
95+
choicec := make(chan api.Organization, 1)
96+
errc := make(chan error, 1)
97+
go func() {
98+
selector := component.Selector[api.Organization]{
99+
Prompt: "Which organization do you want for this test?",
100+
Flag: "--org",
101+
102+
Creatable: true,
103+
104+
Fetcher: &component.Fetcher[api.Organization]{
105+
FetchFn: func() ([]api.Organization, error) { return anc.GetOrgs(ctx) },
106+
},
107+
}
108+
109+
org, err := selector.Choice(ctx, drv)
110+
if err != nil {
111+
errc <- err
112+
return
113+
}
114+
115+
choicec <- *org
116+
errc <- tm.Quit()
117+
}()
118+
119+
uitest.WaitForGoldenContains(t, drv, errc,
120+
"? Which organization do you want for this test?",
121+
)
122+
123+
tm.Send(tea.KeyMsg{
124+
Type: tea.KeyDown,
125+
})
126+
tm.Send(tea.KeyMsg{
127+
Type: tea.KeyEnter,
128+
})
129+
130+
org := <-choicec
131+
132+
if want, got := "", org.Slug; want != got {
133+
t.Errorf("Want org choice: %q, Got: %q", want, got)
134+
}
135+
136+
if err := <-errc; err != nil {
137+
t.Error(err)
138+
}
139+
140+
tm.WaitFinished(t, teatest.WithFinalTimeout(time.Second*3))
141+
uitest.TestGolden(t, drv.Golden())
142+
})
143+
81144
t.Run("orgs double", func(t *testing.T) {
82145
if srv.IsProxy() {
83146
t.Skip("selector tests unsupported in proxy mode")
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
─── Fetcher[github.com/anchordotdev/cli/api.Organization] ──────────────────────
2+
* Fetching organizations…⠋
3+
─── Selector[github.com/anchordotdev/cli/api.Organization] ─────────────────────
4+
? Which organization do you want for this test?
5+
> Solo Org Slug (solo-org-slug)
6+
Create New Organization
7+
─── Selector[github.com/anchordotdev/cli/api.Organization] ─────────────────────
8+
? Which organization do you want for this test?
9+
Solo Org Slug (solo-org-slug)
10+
> Create New Organization
11+
─── Selector[github.com/anchordotdev/cli/api.Organization] ─────────────────────
12+
- Selected Create New Organization.

config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type Config struct {
5858

5959
Org struct {
6060
APID string `env:"ORG" toml:"apid,omitempty"`
61+
Name string `env:"ORG_NAME" toml:",omitempty,readonly"`
6162
} `toml:"org,omitempty"`
6263

6364
Realm struct {

go.mod

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ require (
88
github.com/atotto/clipboard v0.1.4
99
github.com/aymanbagabas/go-udiff v0.2.0
1010
github.com/benburkert/dns v0.0.0-20190225204957-d356cf78cdfc
11-
github.com/brianvoe/gofakeit/v7 v7.0.4
11+
github.com/brianvoe/gofakeit/v7 v7.1.2
1212
github.com/charmbracelet/bubbles v0.20.0
13-
github.com/charmbracelet/bubbletea v1.1.0
14-
github.com/charmbracelet/lipgloss v0.13.0
13+
github.com/charmbracelet/bubbletea v1.1.2
14+
github.com/charmbracelet/lipgloss v1.0.0
1515
github.com/charmbracelet/x/exp/teatest v0.0.0-20240222131549-03ee51df8bea
1616
github.com/cli/browser v1.3.0
17-
github.com/deepmap/oapi-codegen v1.16.3
1817
github.com/fatih/structtag v1.2.0
1918
github.com/go-test/deep v1.1.1
2019
github.com/gofrs/flock v0.12.1
@@ -24,13 +23,14 @@ require (
2423
github.com/mcuadros/go-defaults v1.2.0
2524
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
2625
github.com/muesli/termenv v0.15.2
26+
github.com/oapi-codegen/oapi-codegen/v2 v2.4.1
2727
github.com/oapi-codegen/runtime v1.1.1
2828
github.com/pelletier/go-toml/v2 v2.2.3
2929
github.com/r3labs/diff/v3 v3.0.1
3030
github.com/spf13/cobra v1.8.1
3131
github.com/spf13/pflag v1.0.5
3232
github.com/stretchr/testify v1.9.0
33-
github.com/zalando/go-keyring v0.2.5
33+
github.com/zalando/go-keyring v0.2.6
3434
golang.org/x/crypto v0.28.0
3535
golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81
3636
golang.org/x/sync v0.8.0
@@ -40,25 +40,25 @@ require (
4040
)
4141

4242
require (
43+
al.essio.dev/pkg/shellescape v1.5.1 // indirect
4344
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
44-
github.com/alessio/shellescape v1.4.1 // indirect
4545
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
46-
github.com/charmbracelet/x/ansi v0.2.3 // indirect
46+
github.com/charmbracelet/x/ansi v0.4.2 // indirect
4747
github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b // indirect
4848
github.com/charmbracelet/x/term v0.2.0 // indirect
4949
github.com/cloudflare/circl v1.3.7 // indirect
50-
github.com/danieljoos/wincred v1.2.0 // indirect
50+
github.com/danieljoos/wincred v1.2.2 // indirect
5151
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
52+
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 // indirect
5253
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
53-
github.com/getkin/kin-openapi v0.118.0 // indirect
54-
github.com/go-openapi/jsonpointer v0.20.0 // indirect
55-
github.com/go-openapi/swag v0.22.4 // indirect
54+
github.com/getkin/kin-openapi v0.127.0 // indirect
55+
github.com/go-openapi/jsonpointer v0.21.0 // indirect
56+
github.com/go-openapi/swag v0.23.0 // indirect
5657
github.com/godbus/dbus/v5 v5.1.0 // indirect
57-
github.com/golang/protobuf v1.5.4 // indirect
5858
github.com/google/go-querystring v1.1.0 // indirect
5959
github.com/google/uuid v1.6.0 // indirect
6060
github.com/inconshreveable/mousetrap v1.1.0 // indirect
61-
github.com/invopop/yaml v0.1.0 // indirect
61+
github.com/invopop/yaml v0.3.1 // indirect
6262
github.com/josharian/intern v1.0.0 // indirect
6363
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
6464
github.com/mailru/easyjson v0.7.7 // indirect
@@ -67,19 +67,19 @@ require (
6767
github.com/mattn/go-runewidth v0.0.16 // indirect
6868
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
6969
github.com/muesli/cancelreader v0.2.2 // indirect
70-
github.com/perimeterx/marshmallow v1.1.4 // indirect
70+
github.com/perimeterx/marshmallow v1.1.5 // indirect
7171
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
7272
github.com/rivo/uniseg v0.4.7 // indirect
73-
github.com/rogpeppe/go-internal v1.10.0 // indirect
7473
github.com/sahilm/fuzzy v0.1.1 // indirect
74+
github.com/sergi/go-diff v1.3.1 // indirect
75+
github.com/speakeasy-api/openapi-overlay v0.9.0 // indirect
7576
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
7677
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
78+
github.com/vmware-labs/yaml-jsonpath v0.3.2 // indirect
7779
golang.org/x/mod v0.21.0 // indirect
7880
golang.org/x/net v0.30.0 // indirect
79-
golang.org/x/oauth2 v0.18.0 // indirect
80-
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
81-
google.golang.org/appengine v1.6.8 // indirect
82-
google.golang.org/protobuf v1.34.3-0.20240830093551-013dd178dc9a // indirect
81+
golang.org/x/oauth2 v0.22.0 // indirect
82+
golang.org/x/tools v0.24.0 // indirect
8383
gopkg.in/yaml.v2 v2.4.0 // indirect
8484
gopkg.in/yaml.v3 v3.0.1 // indirect
8585
)

0 commit comments

Comments
 (0)