Compare commits
3 Commits
bad41b431d
...
14cfe33f95
| Author | SHA1 | Date | |
|---|---|---|---|
| 14cfe33f95 | |||
| f356d2f7e1 | |||
| e4088e4aec |
@@ -11,13 +11,11 @@ This tool converts the statements from brokers and exchanges into a format compa
|
||||
## Install
|
||||
|
||||
```bash
|
||||
go install git.naterciomoniz.net/applications/broker2anexoj@latest
|
||||
go install github.com/nmoniz/any2anexoj/cmd/any2anexoj-cli@latest
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
broker2anexoj
|
||||
cat statement.csv | broker2anexoj --platform=tranding212
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -7,31 +7,49 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
|
||||
"git.naterciomoniz.net/applications/broker2anexoj/internal"
|
||||
"git.naterciomoniz.net/applications/broker2anexoj/internal/trading212"
|
||||
"github.com/nmoniz/any2anexoj/internal"
|
||||
"github.com/nmoniz/any2anexoj/internal/trading212"
|
||||
"github.com/spf13/pflag"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
// TODO: once we support more brokers or exchanges we should make this parameter required and
|
||||
// remove/change default
|
||||
var platform = pflag.StringP("platform", "p", "trading212", "one of the supported platforms")
|
||||
|
||||
var supportedPlatforms = map[string]func() internal.RecordReader{
|
||||
"trading212": func() internal.RecordReader { return trading212.NewRecordReader(os.Stdin) },
|
||||
}
|
||||
|
||||
func main() {
|
||||
err := run(context.Background())
|
||||
pflag.Parse()
|
||||
|
||||
if platform == nil || len(*platform) == 0 {
|
||||
slog.Error("--platform flag is required")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err := run(context.Background(), *platform)
|
||||
if err != nil {
|
||||
slog.Error("found a fatal issue", slog.Any("err", err))
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func run(ctx context.Context) error {
|
||||
func run(ctx context.Context, platform string) error {
|
||||
ctx, cancel := signal.NotifyContext(ctx, os.Kill, os.Interrupt)
|
||||
defer cancel()
|
||||
|
||||
eg, ctx := errgroup.WithContext(ctx)
|
||||
|
||||
f, err := os.Open("test.csv")
|
||||
if err != nil {
|
||||
return fmt.Errorf("open statement: %w", err)
|
||||
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, nil)))
|
||||
|
||||
factory, ok := supportedPlatforms[platform]
|
||||
if !ok {
|
||||
return fmt.Errorf("unsupported platform: %s", platform)
|
||||
}
|
||||
|
||||
reader := trading212.NewRecordReader(f)
|
||||
reader := factory()
|
||||
|
||||
writer := internal.NewStdOutLogger()
|
||||
|
||||
@@ -39,7 +57,7 @@ func run(ctx context.Context) error {
|
||||
return internal.BuildReport(ctx, reader, writer)
|
||||
})
|
||||
|
||||
err = eg.Wait()
|
||||
err := eg.Wait()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
3
go.mod
3
go.mod
@@ -1,4 +1,4 @@
|
||||
module git.naterciomoniz.net/applications/broker2anexoj
|
||||
module github.com/nmoniz/any2anexoj
|
||||
|
||||
go 1.25.3
|
||||
|
||||
@@ -8,6 +8,7 @@ require (
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/spf13/pflag v1.0.10 // indirect
|
||||
golang.org/x/mod v0.27.0 // indirect
|
||||
golang.org/x/tools v0.36.0 // indirect
|
||||
)
|
||||
|
||||
2
go.sum
2
go.sum
@@ -4,6 +4,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
|
||||
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y=
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: git.naterciomoniz.net/applications/broker2anexoj/internal (interfaces: RecordReader,Record,ReportWriter)
|
||||
// Source: github.com/nmoniz/any2anexoj/internal (interfaces: RecordReader,Record,ReportWriter)
|
||||
//
|
||||
// Generated by this command:
|
||||
//
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
reflect "reflect"
|
||||
time "time"
|
||||
|
||||
internal "git.naterciomoniz.net/applications/broker2anexoj/internal"
|
||||
internal "github.com/nmoniz/any2anexoj/internal"
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.naterciomoniz.net/applications/broker2anexoj/internal"
|
||||
"git.naterciomoniz.net/applications/broker2anexoj/internal/mocks"
|
||||
"github.com/nmoniz/any2anexoj/internal"
|
||||
"github.com/nmoniz/any2anexoj/internal/mocks"
|
||||
"go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// ReportLogger writes a simple, human readable, line to the provided io.Writer for each
|
||||
// ReportItem received.
|
||||
type ReportLogger struct {
|
||||
counter int
|
||||
writer io.Writer
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.naterciomoniz.net/applications/broker2anexoj/internal"
|
||||
"github.com/nmoniz/any2anexoj/internal"
|
||||
)
|
||||
|
||||
func TestReportLogger_Write(t *testing.T) {
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.naterciomoniz.net/applications/broker2anexoj/internal"
|
||||
"github.com/nmoniz/any2anexoj/internal"
|
||||
)
|
||||
|
||||
type Record struct {
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.naterciomoniz.net/applications/broker2anexoj/internal"
|
||||
"github.com/nmoniz/any2anexoj/internal"
|
||||
)
|
||||
|
||||
func TestRecordReader_ReadRecord(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user