From 4d4b2b877a977d324850a840ca8f5698061dce26 Mon Sep 17 00:00:00 2001 From: Danny Olson Date: Fri, 29 Mar 2024 14:56:26 -0700 Subject: [PATCH] Handle missing SDK instructions --- internal/quickstart/choose_sdk.go | 3 +-- internal/quickstart/container.go | 4 ++++ internal/quickstart/messages.go | 11 +++++++++++ internal/quickstart/show_sdk_instructions.go | 11 +++++------ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/internal/quickstart/choose_sdk.go b/internal/quickstart/choose_sdk.go index c64b91c6..8ba59130 100644 --- a/internal/quickstart/choose_sdk.go +++ b/internal/quickstart/choose_sdk.go @@ -79,8 +79,7 @@ type sdkDetail struct { func (s sdkDetail) FilterValue() string { return "" } var SDKs = []sdkDetail{ - // TODO: react is still internal - // {CanonicalName: "react", DisplayName: "React", SDKType: clientSideSDK}, + {canonicalName: "react", displayName: "React", kind: clientSideSDK}, {canonicalName: "node-server", displayName: "Node.js (server-side)", kind: serverSideSDK}, {canonicalName: "python", displayName: "Python", kind: serverSideSDK}, {canonicalName: "java", displayName: "Java", kind: serverSideSDK}, diff --git a/internal/quickstart/container.go b/internal/quickstart/container.go index 32417214..510c00f5 100644 --- a/internal/quickstart/container.go +++ b/internal/quickstart/container.go @@ -115,6 +115,10 @@ func (m ContainerModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } case errMsg: m.err = msg.err + case noInstructionsMsg: + m.currentStep += 1 + + return m, cmd default: } diff --git a/internal/quickstart/messages.go b/internal/quickstart/messages.go index 63cf6978..c6c5adbb 100644 --- a/internal/quickstart/messages.go +++ b/internal/quickstart/messages.go @@ -8,6 +8,8 @@ type fetchSDKInstructionsMsg struct { name string } +// errMsg is sent when there is an error in one of the steps that the container model needs to +// know about. type errMsg struct { err error } @@ -17,3 +19,12 @@ func sendErr(err error) tea.Cmd { return errMsg{err: err} } } + +// noInstructionsMsg is sent when we can't find the SDK instructions repository for the given SDK. +type noInstructionsMsg struct{} + +func sendNoInstructions() tea.Cmd { + return func() tea.Msg { + return noInstructionsMsg{} + } +} diff --git a/internal/quickstart/show_sdk_instructions.go b/internal/quickstart/show_sdk_instructions.go index 78cbd715..d4067d63 100644 --- a/internal/quickstart/show_sdk_instructions.go +++ b/internal/quickstart/show_sdk_instructions.go @@ -3,7 +3,6 @@ package quickstart import ( "fmt" "io" - "ldcli/internal/errors" "ldcli/internal/sdks" "net/http" "time" @@ -51,14 +50,14 @@ func (m showSDKInstructionsModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, sendErr(err) } - if resp.StatusCode != 200 { - return m, sendErr(errors.NewError(fmt.Sprintf("could not find %s SDK instructions", msg.name))) - } + if resp.StatusCode == 404 { + m.sdk = msg.name - instructions := sdks.ReplaceFlagKey(string(body), msg.flagKey) + return m, sendNoInstructions() + } m.sdk = msg.name - m.instructions = instructions + m.instructions = sdks.ReplaceFlagKey(string(body), msg.flagKey) } return m, nil