update readme and platform param
This commit is contained in:
@@ -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
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -2,31 +2,54 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
||||
"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)
|
||||
|
||||
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, nil)))
|
||||
reader := trading212.NewRecordReader(os.Stdin)
|
||||
|
||||
factory, ok := supportedPlatforms[platform]
|
||||
if !ok {
|
||||
return fmt.Errorf("unsupported platform: %s", platform)
|
||||
}
|
||||
|
||||
reader := factory()
|
||||
|
||||
writer := internal.NewStdOutLogger()
|
||||
|
||||
|
||||
1
go.mod
1
go.mod
@@ -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=
|
||||
|
||||
Reference in New Issue
Block a user