diff --git a/internal/quickstart/messages.go b/internal/quickstart/messages.go index 2abdcba1..816c77a7 100644 --- a/internal/quickstart/messages.go +++ b/internal/quickstart/messages.go @@ -4,13 +4,13 @@ import ( "context" "encoding/json" "fmt" - "os" tea "github.com/charmbracelet/bubbletea" "ldcli/internal/environments" "ldcli/internal/errors" "ldcli/internal/flags" + "ldcli/internal/sdks" ) // errMsg is sent when there is an error in one of the steps that the container model needs to @@ -114,7 +114,7 @@ func chooseSDK(sdk sdkDetail) tea.Cmd { func readSDKInstructions(filename string) tea.Cmd { return func() tea.Msg { - content, err := os.ReadFile(fmt.Sprintf("internal/sdks/sdk_instructions/%s.md", filename)) + content, err := sdks.InstructionFiles.ReadFile(fmt.Sprintf("sdk_instructions/%s.md", filename)) if err != nil { return errMsg{err: err} } diff --git a/internal/quickstart/show_sdk_instructions.go b/internal/quickstart/show_sdk_instructions.go index 97ef286b..1c791129 100644 --- a/internal/quickstart/show_sdk_instructions.go +++ b/internal/quickstart/show_sdk_instructions.go @@ -2,6 +2,7 @@ package quickstart import ( "fmt" + "github.com/charmbracelet/bubbles/help" "github.com/charmbracelet/bubbles/key" "github.com/charmbracelet/bubbles/spinner" @@ -32,6 +33,7 @@ type showSDKInstructionsModel struct { displayName string environment *environment environmentsClient environments.Client + err error flagKey string help help.Model helpKeys keyMap @@ -63,7 +65,6 @@ func NewShowSDKInstructionsModel( PaddingRight(2) h := help.New() - h.ShowAll = true return showSDKInstructionsModel{ accessToken: accessToken, @@ -129,15 +130,24 @@ func (m showSDKInstructionsModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.viewport.SetContent(md) case spinner.TickMsg: m.spinner, cmd = m.spinner.Update(msg) + case errMsg: + m.err = msg.err } return m, cmd } func (m showSDKInstructionsModel) View() string { + if m.err != nil { + return footerView(m.help.View(m.helpKeys), m.err) + } + if m.instructions == "" || m.environment == nil { - return m.spinner.View() + fmt.Sprintf(" Fetching %s SDK instructions...", m.displayName) + return m.spinner.View() + fmt.Sprintf(" Fetching %s SDK instructions...\n", m.displayName) + footerView(m.help.View(m.helpKeys), nil) } + + m.help.ShowAll = true + instructions := fmt.Sprintf(` Here are the steps to set up a test app to see feature flagging in action using the %s SDK in your Default project & Test environment. diff --git a/internal/sdks/sdks.go b/internal/sdks/sdks.go index 48030b98..ea503743 100644 --- a/internal/sdks/sdks.go +++ b/internal/sdks/sdks.go @@ -1,10 +1,14 @@ package sdks import ( + "embed" "regexp" "strings" ) +//go:embed sdk_instructions/*.md +var InstructionFiles embed.FS + // ReplaceFlagKey changes the placeholder flag key in the SDK instructions to the flag key from // the user. func ReplaceFlagKey(instructions string, key string) string {