Skip to content

Commit fb468e6

Browse files
committed
feat: list available releases when selecting local
1 parent 3c57991 commit fb468e6

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

models/weaveinit/run_l1_node.go

+30-18
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os/exec"
77
"path/filepath"
88
"runtime"
9+
"sort"
910
"strings"
1011
"time"
1112

@@ -61,7 +62,7 @@ func (m *RunL1NodeNetworkSelect) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
6162
case Mainnet, Testnet:
6263
return NewRunL1NodeMonikerInput(m.state), cmd
6364
case Local:
64-
return NewRunL1NodeVersionInput(m.state), nil
65+
return NewRunL1NodeVersionSelect(m.state), nil
6566
}
6667
return m, tea.Quit
6768
}
@@ -73,41 +74,52 @@ func (m *RunL1NodeNetworkSelect) View() string {
7374
return styles.RenderPrompt("Which network will your node participate in?", []string{"network"}, styles.Question) + m.Selector.View()
7475
}
7576

76-
type RunL1NodeVersionInput struct {
77-
utils.TextInput
77+
type RunL1NodeVersionSelect struct {
78+
utils.Selector[string]
7879
state *RunL1NodeState
80+
versions utils.InitiaVersionWithDownloadURL
7981
question string
8082
}
8183

82-
func NewRunL1NodeVersionInput(state *RunL1NodeState) *RunL1NodeVersionInput {
83-
return &RunL1NodeVersionInput{
84-
TextInput: utils.NewTextInput(),
85-
state: state,
86-
question: "Please specify the initiad version",
84+
func NewRunL1NodeVersionSelect(state *RunL1NodeState) *RunL1NodeVersionSelect {
85+
versions := utils.ListInitiaReleases()
86+
options := make([]string, 0, len(versions))
87+
for key := range versions {
88+
options = append(options, key)
89+
}
90+
sort.Sort(sort.Reverse(sort.StringSlice(options)))
91+
return &RunL1NodeVersionSelect{
92+
Selector: utils.Selector[string]{
93+
Options: options,
94+
},
95+
state: state,
96+
versions: versions,
97+
question: "Which network will your node participate in?",
8798
}
8899
}
89100

90-
func (m *RunL1NodeVersionInput) GetQuestion() string {
101+
func (m *RunL1NodeVersionSelect) GetQuestion() string {
91102
return m.question
92103
}
93104

94-
func (m *RunL1NodeVersionInput) Init() tea.Cmd {
105+
func (m *RunL1NodeVersionSelect) Init() tea.Cmd {
95106
return nil
96107
}
97108

98-
func (m *RunL1NodeVersionInput) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
99-
input, cmd, done := m.TextInput.Update(msg)
100-
if done {
101-
m.state.initiadVersion = input.Text
102-
m.state.weave.PreviousResponse += styles.RenderPreviousResponse(styles.DotsSeparator, m.GetQuestion(), []string{"initiad version"}, input.Text)
109+
func (m *RunL1NodeVersionSelect) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
110+
selected, cmd := m.Select(msg)
111+
if selected != nil {
112+
m.state.initiadVersion = *selected
113+
m.state.initiadEndpoint = m.versions[*selected]
114+
m.state.weave.PreviousResponse += styles.RenderPreviousResponse(styles.DotsSeparator, m.GetQuestion(), []string{"initiad version"}, m.state.initiadVersion)
103115
return NewRunL1NodeChainIdInput(m.state), cmd
104116
}
105-
m.TextInput = input
117+
106118
return m, cmd
107119
}
108120

109-
func (m *RunL1NodeVersionInput) View() string {
110-
return m.state.weave.PreviousResponse + styles.RenderPrompt(m.GetQuestion(), []string{"initiad version"}, styles.Question) + m.TextInput.View()
121+
func (m *RunL1NodeVersionSelect) View() string {
122+
return styles.RenderPrompt("Which network will your node participate in?", []string{"network"}, styles.Question) + m.Selector.View()
111123
}
112124

113125
type RunL1NodeChainIdInput struct {

models/weaveinit/state.go

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ type RunL1NodeState struct {
66
weave types.WeaveState
77
network string
88
initiadVersion string
9+
initiadEndpoint string
910
chainId string
1011
moniker string
1112
existingApp bool

0 commit comments

Comments
 (0)