-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* read sdk instructions from md file * fix article typo * add text wrapping to view step * add comment * fix python md
- Loading branch information
1 parent
88765a2
commit c4dc7d0
Showing
5 changed files
with
183 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
## Build Instructions | ||
1. Edit `index.html` and set the value of `clientSideID` to your LaunchDarkly client-side ID. If there is an existing boolean feature flag in your LaunchDarkly project that you want to evaluate, set `flagKey` to the flag key. | ||
|
||
``` | ||
const clientSideID = '1234567890abcdef'; | ||
const flagKey = 'my-flag-key'; | ||
``` | ||
|
||
2. Open `index.html` in your browser. | ||
|
||
You should receive the message "Feature flag key '<flag key>' is <true/false> for this user". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## Build instructions | ||
|
||
1. Install the LaunchDarkly Python SDK by running `pip install -r requirements.txt` | ||
2. On the command line, set the value of the environment variable `LAUNCHDARKLY_SERVER_KEY` to your LaunchDarkly SDK key. | ||
```bash | ||
export LAUNCHDARKLY_SERVER_KEY="1234567890abcdef" | ||
``` | ||
3. On the command line, set the value of the environment variable `LAUNCHDARKLY_FLAG_KEY` to an existing boolean feature flag in your LaunchDarkly project that you want to evaluate. | ||
|
||
```bash | ||
export LAUNCHDARKLY_FLAG_KEY="my-flag-key" | ||
``` | ||
4. Run `python test.py`. | ||
|
||
You should receive the message `"Feature flag 'my-flag-key' is <true/false> for this user"`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package setup | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"strings" | ||
|
||
"github.com/charmbracelet/bubbles/key" | ||
"github.com/charmbracelet/bubbles/list" | ||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/charmbracelet/lipgloss" | ||
) | ||
|
||
var ( | ||
sdkStyle = lipgloss.NewStyle().PaddingLeft(4) | ||
selectedSdkItemStyle = lipgloss.NewStyle().PaddingLeft(2).Foreground(lipgloss.Color("170")) | ||
|
||
_ list.Item = sdk{} | ||
) | ||
|
||
type sdk struct { | ||
Name string `json:"name"` | ||
InstructionsFileName string `json:"instructionFile"` | ||
} | ||
|
||
func (s sdk) FilterValue() string { return "" } | ||
|
||
type sdkModel struct { | ||
choice sdk | ||
instructions string | ||
err error | ||
list list.Model | ||
} | ||
|
||
const sdkInstructionsFilePath = "internal/setup/sdk_build_instructions/" | ||
|
||
func NewSdk() tea.Model { | ||
sdks := []sdk{ | ||
{ | ||
Name: "JavaScript", | ||
InstructionsFileName: sdkInstructionsFilePath + "js.md", | ||
}, | ||
{ | ||
Name: "Python", | ||
InstructionsFileName: sdkInstructionsFilePath + "python.md", | ||
}, | ||
} | ||
|
||
l := list.New(sdksToItems(sdks), sdkDelegate{}, 30, 14) | ||
l.Title = "Select your SDK." | ||
l.SetShowStatusBar(false) | ||
l.SetFilteringEnabled(false) | ||
|
||
return sdkModel{ | ||
list: l, | ||
} | ||
} | ||
|
||
func (p sdkModel) Init() tea.Cmd { | ||
return nil | ||
} | ||
|
||
// This method has drifted from the ProjectModel's version, but it should do something similar. | ||
func (m sdkModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | ||
var cmd tea.Cmd | ||
switch msg := msg.(type) { | ||
case tea.KeyMsg: | ||
switch { | ||
case key.Matches(msg, keys.Enter): | ||
i, ok := m.list.SelectedItem().(sdk) | ||
if ok { | ||
m.choice = i | ||
} | ||
case key.Matches(msg, keys.Quit): | ||
return m, tea.Quit | ||
default: | ||
m.list, cmd = m.list.Update(msg) | ||
} | ||
} | ||
|
||
return m, cmd | ||
} | ||
|
||
func (m sdkModel) View() string { | ||
return "\n" + m.list.View() | ||
} | ||
|
||
type sdkDelegate struct{} | ||
|
||
func (d sdkDelegate) Height() int { return 1 } | ||
func (d sdkDelegate) Spacing() int { return 0 } | ||
func (d sdkDelegate) Update(_ tea.Msg, _ *list.Model) tea.Cmd { return nil } | ||
func (d sdkDelegate) Render(w io.Writer, m list.Model, index int, listItem list.Item) { | ||
i, ok := listItem.(sdk) | ||
if !ok { | ||
return | ||
} | ||
|
||
str := fmt.Sprintf("%d. %s", index+1, i.Name) | ||
|
||
fn := sdkStyle.Render | ||
if index == m.Index() { | ||
fn = func(s ...string) string { | ||
return selectedSdkItemStyle.Render("> " + strings.Join(s, " ")) | ||
} | ||
} | ||
|
||
fmt.Fprint(w, fn(str)) | ||
} | ||
|
||
func sdksToItems(sdks []sdk) []list.Item { | ||
items := make([]list.Item, len(sdks)) | ||
for i, proj := range sdks { | ||
items[i] = list.Item(proj) | ||
} | ||
|
||
return items | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters