sqs-browse: Added dynamo-browse
Added another tool for browsing DynamoDB tables
This commit is contained in:
parent
2c03f5160a
commit
1969504611
14 changed files with 477 additions and 4 deletions
65
cmd/dynamo-browse/main.go
Normal file
65
cmd/dynamo-browse/main.go
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/aws/aws-sdk-go-v2/config"
|
||||
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/lmika/awstools/internal/dynamo-browse/providers/dynamo"
|
||||
"github.com/lmika/awstools/internal/dynamo-browse/services/tables"
|
||||
"github.com/lmika/awstools/internal/dynamo-browse/ui"
|
||||
"github.com/lmika/gopkgs/cli"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var flagTable = flag.String("t", "", "dynamodb table name")
|
||||
var flagLocal = flag.Bool("local", false, "local endpoint")
|
||||
flag.Parse()
|
||||
|
||||
ctx := context.Background()
|
||||
cfg, err := config.LoadDefaultConfig(ctx)
|
||||
if err != nil {
|
||||
cli.Fatalf("cannot load AWS config: %v", err)
|
||||
}
|
||||
|
||||
var dynamoClient *dynamodb.Client
|
||||
if *flagLocal {
|
||||
dynamoClient = dynamodb.NewFromConfig(cfg,
|
||||
dynamodb.WithEndpointResolver(dynamodb.EndpointResolverFromURL("http://localhost:8000")))
|
||||
} else {
|
||||
dynamoClient = dynamodb.NewFromConfig(cfg)
|
||||
}
|
||||
|
||||
dynamoProvider := dynamo.NewProvider(dynamoClient)
|
||||
|
||||
tableService := tables.NewService(dynamoProvider)
|
||||
|
||||
loopback := &msgLoopback{}
|
||||
uiModel := ui.NewModel(tableService, loopback, *flagTable)
|
||||
p := tea.NewProgram(uiModel, tea.WithAltScreen())
|
||||
loopback.program = p
|
||||
|
||||
f, err := tea.LogToFile("debug.log", "debug")
|
||||
if err != nil {
|
||||
fmt.Println("fatal:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
if err := p.Start(); err != nil {
|
||||
fmt.Printf("Alas, there's been an error: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
type msgLoopback struct {
|
||||
program *tea.Program
|
||||
}
|
||||
|
||||
func (m *msgLoopback) Send(msg tea.Msg) {
|
||||
m.program.Send(msg)
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue