A few various changes
- Fixed the '-local' flag to accept host and port - Added a '-debug' flag to accept a file to write debug log messages - Added some logic which will force the dark background flag on if MacOS is in dark mode
This commit is contained in:
parent
47e404aff7
commit
41af399215
18 changed files with 191 additions and 68 deletions
|
|
@ -31,6 +31,15 @@ func PromptForInput(prompt string, onDone func(value string) tea.Cmd) tea.Cmd {
|
|||
}
|
||||
}
|
||||
|
||||
func Confirm(prompt string, onYes func() tea.Cmd) tea.Cmd {
|
||||
return PromptForInput(prompt, func(value string) tea.Cmd {
|
||||
if value == "y" {
|
||||
return onYes()
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
type MessageWithStatus interface {
|
||||
StatusMessage() string
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,15 +6,18 @@ import (
|
|||
"os"
|
||||
)
|
||||
|
||||
func EnableLogging() (closeFn func()) {
|
||||
tempFile, err := os.CreateTemp("", "debug.log")
|
||||
if err != nil {
|
||||
fmt.Println("fatal:", err)
|
||||
os.Exit(1)
|
||||
func EnableLogging(logFile string) (closeFn func()) {
|
||||
if logFile == "" {
|
||||
tempFile, err := os.CreateTemp("", "debug.log")
|
||||
if err != nil {
|
||||
fmt.Println("fatal:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
tempFile.Close()
|
||||
logFile = tempFile.Name()
|
||||
}
|
||||
tempFile.Close()
|
||||
|
||||
f, err := tea.LogToFile(tempFile.Name(), "debug")
|
||||
f, err := tea.LogToFile(logFile, "debug")
|
||||
if err != nil {
|
||||
fmt.Println("fatal:", err)
|
||||
os.Exit(1)
|
||||
|
|
|
|||
18
internal/common/ui/osstyle/osstyle.go
Normal file
18
internal/common/ui/osstyle/osstyle.go
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package osstyle
|
||||
|
||||
type ColorScheme int
|
||||
|
||||
const (
|
||||
ColorSchemeUnknown ColorScheme = iota
|
||||
ColorSchemeLightMode
|
||||
ColorSchemeDarkMode
|
||||
)
|
||||
|
||||
var getOSColorScheme func() ColorScheme = nil
|
||||
|
||||
func CurrentColorScheme() ColorScheme {
|
||||
if getOSColorScheme == nil {
|
||||
return ColorSchemeUnknown
|
||||
}
|
||||
return getOSColorScheme()
|
||||
}
|
||||
27
internal/common/ui/osstyle/osstyle_darwin.go
Normal file
27
internal/common/ui/osstyle/osstyle_darwin.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package osstyle
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// Usage: https://stefan.sofa-rockers.org/2018/10/23/macos-dark-mode-terminal-vim/
|
||||
func darwinGetOSColorScheme() ColorScheme {
|
||||
d, err := exec.Command("defaults", "read", "-g", "AppleInterfaceStyle").Output()
|
||||
if err != nil {
|
||||
log.Printf("cannot get current OS color scheme: %v", err)
|
||||
return ColorSchemeUnknown
|
||||
}
|
||||
|
||||
switch string(d) {
|
||||
case "Dark\n":
|
||||
return ColorSchemeDarkMode
|
||||
case "Light\n":
|
||||
return ColorSchemeLightMode
|
||||
}
|
||||
return ColorSchemeUnknown
|
||||
}
|
||||
|
||||
func init() {
|
||||
getOSColorScheme = darwinGetOSColorScheme
|
||||
}
|
||||
|
|
@ -1,18 +1,18 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/lmika/awstools/internal/dynamo-browse/models"
|
||||
)
|
||||
|
||||
type NewResultSet struct {
|
||||
ResultSet *models.ResultSet
|
||||
ResultSet *models.ResultSet
|
||||
statusMessage string
|
||||
}
|
||||
|
||||
func (rs NewResultSet) StatusMessage() string {
|
||||
return fmt.Sprintf("%d items returned", len(rs.ResultSet.Items()))
|
||||
//return fmt.Sprintf("%d items returned", len(rs.ResultSet.Items()))
|
||||
return rs.statusMessage
|
||||
}
|
||||
|
||||
type SetReadWrite struct {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package controllers
|
|||
import (
|
||||
"context"
|
||||
"encoding/csv"
|
||||
"fmt"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/lmika/awstools/internal/common/ui/events"
|
||||
"github.com/lmika/awstools/internal/dynamo-browse/models"
|
||||
|
|
@ -126,16 +127,23 @@ func (c *TableReadController) doScan(ctx context.Context, resultSet *models.Resu
|
|||
return c.setResultSetAndFilter(newResultSet, c.state.Filter())
|
||||
}
|
||||
|
||||
//func (c *TableReadController) ResultSet() *models.ResultSet {
|
||||
// c.mutex.Lock()
|
||||
// defer c.mutex.Unlock()
|
||||
//
|
||||
// return c.resultSet
|
||||
//}
|
||||
|
||||
func (c *TableReadController) setResultSetAndFilter(resultSet *models.ResultSet, filter string) tea.Msg {
|
||||
c.state.setResultSetAndFilter(resultSet, filter)
|
||||
return NewResultSet{resultSet}
|
||||
|
||||
var statusMessage string
|
||||
if filter != "" {
|
||||
var filteredCount int
|
||||
for i := range resultSet.Items() {
|
||||
if !resultSet.Hidden(i) {
|
||||
filteredCount += 1
|
||||
}
|
||||
}
|
||||
statusMessage = fmt.Sprintf("%d of %d items returned", filteredCount, len(resultSet.Items()))
|
||||
} else {
|
||||
statusMessage = fmt.Sprintf("%d items returned", len(resultSet.Items()))
|
||||
}
|
||||
|
||||
return NewResultSet{resultSet, statusMessage}
|
||||
}
|
||||
|
||||
func (c *TableReadController) Unmark() tea.Cmd {
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ func (twc *TableWriteController) NewItem() tea.Cmd {
|
|||
Dirty: true,
|
||||
})
|
||||
})
|
||||
return NewResultSet{twc.state.ResultSet()}
|
||||
return NewResultSet{twc.state.ResultSet(), "New item added"}
|
||||
}
|
||||
|
||||
return keyPrompts.next()
|
||||
|
|
|
|||
|
|
@ -128,9 +128,7 @@ func (m *Model) setLeftmostDisplayedColumn(newCol int) {
|
|||
} else {
|
||||
m.colOffset = newCol
|
||||
}
|
||||
// TEMP
|
||||
m.table.GoDown()
|
||||
m.table.GoUp()
|
||||
m.table.UpdateView()
|
||||
}
|
||||
|
||||
func (m *Model) View() string {
|
||||
|
|
@ -172,15 +170,6 @@ func (m *Model) rebuildTable() {
|
|||
|
||||
m.rows = newRows
|
||||
newTbl.SetRows(newRows)
|
||||
/*
|
||||
for newTbl.Cursor() != m.table.Cursor() {
|
||||
if newTbl.Cursor() < m.table.Cursor() {
|
||||
newTbl.GoDown()
|
||||
} else if newTbl.Cursor() > m.table.Cursor() {
|
||||
newTbl.GoUp()
|
||||
}
|
||||
}
|
||||
*/
|
||||
m.table = newTbl
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import (
|
|||
|
||||
var (
|
||||
markedRowStyle = lipgloss.NewStyle().
|
||||
Background(lipgloss.AdaptiveColor{Dark: "#e1e1e1", Light: "#414141"})
|
||||
Background(lipgloss.AdaptiveColor{Light: "#e1e1e1", Dark: "#414141"})
|
||||
dirtyRowStyle = lipgloss.NewStyle().
|
||||
Foreground(lipgloss.Color("#e13131"))
|
||||
newRowStyle = lipgloss.NewStyle().
|
||||
|
|
@ -60,6 +60,8 @@ func (mtr itemTableRow) Render(w io.Writer, model table.Model, index int) {
|
|||
if mi := r.MetaInfo(); mi != "" {
|
||||
sb.WriteString(metaInfoStyle.Render(mi))
|
||||
}
|
||||
} else {
|
||||
sb.WriteString(metaInfoStyle.Render("~"))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -77,3 +77,24 @@ func (c *SSMController) Clone(param models.SSMParameter) tea.Cmd {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (c *SSMController) DeleteParameter(param models.SSMParameter) tea.Cmd {
|
||||
return events.Confirm("delete parameter? ", func() tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
ctx := context.Background()
|
||||
if err := c.service.Delete(ctx, param); err != nil {
|
||||
return events.Error(err)
|
||||
}
|
||||
|
||||
res, err := c.service.List(context.Background(), c.prefix)
|
||||
if err != nil {
|
||||
return events.Error(err)
|
||||
}
|
||||
|
||||
return NewParameterListMsg{
|
||||
Prefix: c.prefix,
|
||||
Parameters: res,
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,9 +56,9 @@ outer:
|
|||
|
||||
func (p *Provider) Put(ctx context.Context, param models.SSMParameter, override bool) error {
|
||||
in := &ssm.PutParameterInput{
|
||||
Name: aws.String(param.Name),
|
||||
Type: param.Type,
|
||||
Value: aws.String(param.Value),
|
||||
Name: aws.String(param.Name),
|
||||
Type: param.Type,
|
||||
Value: aws.String(param.Value),
|
||||
Overwrite: override,
|
||||
}
|
||||
if param.Type == types.ParameterTypeSecureString {
|
||||
|
|
@ -71,4 +71,14 @@ func (p *Provider) Put(ctx context.Context, param models.SSMParameter, override
|
|||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Provider) Delete(ctx context.Context, param models.SSMParameter) error {
|
||||
_, err := p.client.DeleteParameter(ctx, &ssm.DeleteParameterInput{
|
||||
Name: aws.String(param.Name),
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unable to delete SSM parameter")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,4 +8,5 @@ import (
|
|||
type SSMProvider interface {
|
||||
List(ctx context.Context, prefix string, maxCount int) (*models.SSMParameters, error)
|
||||
Put(ctx context.Context, param models.SSMParameter, override bool) error
|
||||
Delete(ctx context.Context, param models.SSMParameter) error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,9 +21,13 @@ func (s *Service) List(ctx context.Context, prefix string) (*models.SSMParameter
|
|||
|
||||
func (s *Service) Clone(ctx context.Context, param models.SSMParameter, newName string) error {
|
||||
newParam := models.SSMParameter{
|
||||
Name: newName,
|
||||
Type: param.Type,
|
||||
Name: newName,
|
||||
Type: param.Type,
|
||||
Value: param.Value,
|
||||
}
|
||||
return s.provider.Put(ctx, newParam, false)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) Delete(ctx context.Context, param models.SSMParameter) error {
|
||||
return s.provider.Delete(ctx, param)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,12 @@ func NewModel(controller *controllers.SSMController, cmdController *commandctrl.
|
|||
}
|
||||
return events.SetError(errors.New("no parameter selected"))
|
||||
},
|
||||
"delete": func(args []string) tea.Cmd {
|
||||
if currentParam := ssmList.CurrentParameter(); currentParam != nil {
|
||||
return controller.DeleteParameter(*currentParam)
|
||||
}
|
||||
return events.SetError(errors.New("no parameter selected"))
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue