Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX-11: Fix constructing connect command #21

Merged
merged 1 commit into from
Nov 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions internal/ui/component/hostlist/list.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package hostlist implements the host list view.
package hostlist

import (
Expand Down Expand Up @@ -29,29 +30,34 @@
}

type (
MsgEditItem struct{ HostID int }
MsgCopyItem struct{ HostID int }
MsgSelectItem struct{ HostID int }
// MsgEditItem fires when user press edit button.
MsgEditItem struct{ HostID int }
// MsgCopyItem fires when user press copy button.
MsgCopyItem struct{ HostID int }
// MsgSelectItem is required to let host list know that it's time to update title.
MsgSelectItem struct{ HostID int }
// MsgNewItem fires when user press new host button.
MsgNewItem struct{}
msgInitComplete struct{}
msgErrorOccured struct{ err error }
// MsgRepoUpdated - fires when data layer updated and it's required to reload the host list.
MsgRepoUpdated struct{}
msgFocusChanged struct{}
)

type ListModel struct {
type listModel struct {
innerModel list.Model
repo storage.HostStorage
keyMap *keyMap
appState *state.ApplicationState
logger logger
}

func New(_ context.Context, storage storage.HostStorage, appState *state.ApplicationState, log logger) ListModel {
func New(_ context.Context, storage storage.HostStorage, appState *state.ApplicationState, log logger) listModel {

Check warning on line 56 in internal/ui/component/hostlist/list.go

View check run for this annotation

Codecov / codecov/patch

internal/ui/component/hostlist/list.go#L56

Added line #L56 was not covered by tests
delegate := list.NewDefaultDelegate()
delegateKeys := newDelegateKeyMap()
listItems := []list.Item{}
m := ListModel{
m := listModel{

Check warning on line 60 in internal/ui/component/hostlist/list.go

View check run for this annotation

Codecov / codecov/patch

internal/ui/component/hostlist/list.go#L60

Added line #L60 was not covered by tests
innerModel: list.New(listItems, delegate, 0, 0),
keyMap: delegateKeys,
repo: storage,
Expand All @@ -73,11 +79,11 @@
return m
}

func (m ListModel) Init() tea.Cmd {
func (m listModel) Init() tea.Cmd {

Check warning on line 82 in internal/ui/component/hostlist/list.go

View check run for this annotation

Codecov / codecov/patch

internal/ui/component/hostlist/list.go#L82

Added line #L82 was not covered by tests
return tea.Batch(message.TeaCmd(msgInitComplete{}))
}

func (m ListModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m listModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

Check warning on line 86 in internal/ui/component/hostlist/list.go

View check run for this annotation

Codecov / codecov/patch

internal/ui/component/hostlist/list.go#L86

Added line #L86 was not covered by tests
var cmds []tea.Cmd

switch msg := msg.(type) {
Expand Down Expand Up @@ -129,11 +135,11 @@
return m, tea.Batch(cmds...)
}

func (m ListModel) View() string {
func (m listModel) View() string {

Check warning on line 138 in internal/ui/component/hostlist/list.go

View check run for this annotation

Codecov / codecov/patch

internal/ui/component/hostlist/list.go#L138

Added line #L138 was not covered by tests
return docStyle.Render(m.innerModel.View())
}

func (m ListModel) removeItem(_ tea.Msg) (ListModel, tea.Cmd) {
func (m listModel) removeItem(_ tea.Msg) (listModel, tea.Cmd) {

Check warning on line 142 in internal/ui/component/hostlist/list.go

View check run for this annotation

Codecov / codecov/patch

internal/ui/component/hostlist/list.go#L142

Added line #L142 was not covered by tests
item, ok := m.innerModel.SelectedItem().(ListItemHost)
if !ok {
return m, message.TeaCmd(msgErrorOccured{err: errors.New("you must select an item")})
Expand All @@ -150,7 +156,7 @@
)
}

func (m ListModel) refreshRepo(_ tea.Msg) (ListModel, tea.Cmd) {
func (m listModel) refreshRepo(_ tea.Msg) (listModel, tea.Cmd) {

Check warning on line 159 in internal/ui/component/hostlist/list.go

View check run for this annotation

Codecov / codecov/patch

internal/ui/component/hostlist/list.go#L159

Added line #L159 was not covered by tests
items := []list.Item{}
hosts, err := m.repo.GetAll()
if err != nil {
Expand Down Expand Up @@ -184,7 +190,7 @@
return m, tea.Batch(setItemsCmd, message.TeaCmd(msgFocusChanged{}))
}

func (m ListModel) editItem(_ tea.Msg) (ListModel, tea.Cmd) {
func (m listModel) editItem(_ tea.Msg) (listModel, tea.Cmd) {

Check warning on line 193 in internal/ui/component/hostlist/list.go

View check run for this annotation

Codecov / codecov/patch

internal/ui/component/hostlist/list.go#L193

Added line #L193 was not covered by tests
item, ok := m.innerModel.SelectedItem().(ListItemHost)
if !ok {
return m, message.TeaCmd(msgErrorOccured{err: errors.New(itemNotSelectedMessage)})
Expand All @@ -194,7 +200,7 @@
return m, message.TeaCmd(MsgEditItem{HostID: host.ID})
}

func (m ListModel) copyItem(_ tea.Msg) (ListModel, tea.Cmd) {
func (m listModel) copyItem(_ tea.Msg) (listModel, tea.Cmd) {

Check warning on line 203 in internal/ui/component/hostlist/list.go

View check run for this annotation

Codecov / codecov/patch

internal/ui/component/hostlist/list.go#L203

Added line #L203 was not covered by tests
item, ok := m.innerModel.SelectedItem().(ListItemHost)
if !ok {
return m, message.TeaCmd(msgErrorOccured{err: errors.New(itemNotSelectedMessage)})
Expand Down Expand Up @@ -225,7 +231,7 @@
)
}

func (m ListModel) executeCmd(_ tea.Msg) (ListModel, tea.Cmd) {
func (m listModel) executeCmd(_ tea.Msg) (listModel, tea.Cmd) {

Check warning on line 234 in internal/ui/component/hostlist/list.go

View check run for this annotation

Codecov / codecov/patch

internal/ui/component/hostlist/list.go#L234

Added line #L234 was not covered by tests
item, ok := m.innerModel.SelectedItem().(ListItemHost)
if !ok {
return m, message.TeaCmd(msgErrorOccured{err: errors.New(itemNotSelectedMessage)})
Expand All @@ -237,7 +243,7 @@
return m, message.TeaCmd(msgErrorOccured{err})
}

command := ssh.ConstructCMD(ssh.BaseCMD(), utils.HostModelToOptionsAdaptor(host))
command := ssh.ConstructCMD(ssh.BaseCMD(), utils.HostModelToOptionsAdaptor(host)...)

Check warning on line 246 in internal/ui/component/hostlist/list.go

View check run for this annotation

Codecov / codecov/patch

internal/ui/component/hostlist/list.go#L246

Added line #L246 was not covered by tests
process := utils.BuildProcess(command)
return m, tea.ExecProcess(process, func(err error) tea.Msg {
if err != nil {
Expand All @@ -248,7 +254,7 @@
})
}

func (m ListModel) listTitleUpdate(msg tea.Msg) ListModel {
func (m listModel) listTitleUpdate(msg tea.Msg) listModel {

Check warning on line 257 in internal/ui/component/hostlist/list.go

View check run for this annotation

Codecov / codecov/patch

internal/ui/component/hostlist/list.go#L257

Added line #L257 was not covered by tests
switch msg := msg.(type) {
case msgErrorOccured:
m.innerModel.Title = msg.err.Error()
Expand All @@ -266,7 +272,7 @@
}
}

func (m ListModel) onFocusChanged(_ tea.Msg) (ListModel, tea.Cmd) {
func (m listModel) onFocusChanged(_ tea.Msg) (listModel, tea.Cmd) {

Check warning on line 275 in internal/ui/component/hostlist/list.go

View check run for this annotation

Codecov / codecov/patch

internal/ui/component/hostlist/list.go#L275

Added line #L275 was not covered by tests
if hostItem, ok := m.innerModel.SelectedItem().(ListItemHost); ok {
return m, message.TeaCmd(MsgSelectItem{HostID: hostItem.ID})
}
Expand Down
Loading