ssm-browse: added cd command

Also came up with an approach for dealing with commands that will probably work with contexts
This commit is contained in:
Leon Mika 2022-03-29 10:29:25 +11:00
parent 0b745a6dfa
commit f6f06eb22d
13 changed files with 142 additions and 37 deletions

View file

@ -3,5 +3,6 @@ package controllers
import "github.com/lmika/awstools/internal/ssm-browse/models"
type NewParameterListMsg struct {
Prefix string
Parameters *models.SSMParameters
}

View file

@ -5,27 +5,53 @@ import (
tea "github.com/charmbracelet/bubbletea"
"github.com/lmika/awstools/internal/common/ui/events"
"github.com/lmika/awstools/internal/ssm-browse/services/ssmparameters"
"sync"
)
type SSMController struct {
service *ssmparameters.Service
// state
mutex *sync.Mutex
prefix string
}
func New(service *ssmparameters.Service) *SSMController {
return &SSMController{
service: service,
prefix: "/",
mutex: new(sync.Mutex),
}
}
func (c *SSMController) Fetch() tea.Cmd {
return func() tea.Msg {
res, err := c.service.List(context.Background())
res, err := c.service.List(context.Background(), c.prefix)
if err != nil {
return events.Error(err)
}
return NewParameterListMsg{
Prefix: c.prefix,
Parameters: res,
}
}
}
func (c *SSMController) ChangePrefix(newPrefix string) tea.Cmd {
return func() tea.Msg {
res, err := c.service.List(context.Background(), newPrefix)
if err != nil {
return events.Error(err)
}
c.mutex.Lock()
defer c.mutex.Unlock()
c.prefix = newPrefix
return NewParameterListMsg{
Prefix: c.prefix,
Parameters: res,
}
}
}