Skip to content

Commit

Permalink
fix: embed instructions files & show error during show sdk step (#174)
Browse files Browse the repository at this point in the history
* show error in show sdk step

* embed instruction files

* only show err on show sdk step

* fix imports

* fix show sdk help view
  • Loading branch information
k3llymariee authored Apr 16, 2024
1 parent a6d79ad commit ae07b46
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/quickstart/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -148,7 +148,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}
}
Expand Down
14 changes: 12 additions & 2 deletions internal/quickstart/show_sdk_instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package quickstart

import (
"fmt"

"github.com/charmbracelet/bubbles/help"
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/spinner"
Expand Down Expand Up @@ -32,6 +33,7 @@ type showSDKInstructionsModel struct {
displayName string
environment *environment
environmentsClient environments.Client
err error
flagKey string
help help.Model
helpKeys keyMap
Expand Down Expand Up @@ -63,7 +65,6 @@ func NewShowSDKInstructionsModel(
PaddingRight(2)

h := help.New()
h.ShowAll = true

return showSDKInstructionsModel{
accessToken: accessToken,
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions internal/sdks/sdks.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit ae07b46

Please sign in to comment.