support some filtering
This commit is contained in:
@@ -16,21 +16,32 @@ import (
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
// 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 (
|
||||
// TODO: once we support more brokers or exchanges we should make this parameter required and
|
||||
// remove/change default
|
||||
platform = pflag.StringP("platform", "p", "trading212", "One of the supported platforms")
|
||||
lang = pflag.StringP("language", "l", language.Portuguese.String(), "The 2 letter language code")
|
||||
// TODO: improve documentation on selectors
|
||||
selectors = pflag.StringSlice("selectors", nil, "Only process entries that conform to all the selectors:")
|
||||
|
||||
var lang = pflag.StringP("language", "l", language.Portuguese.String(), "2 letter language code")
|
||||
|
||||
var readerFactories = map[string]func() internal.RecordReader{
|
||||
"trading212": func() internal.RecordReader {
|
||||
return trading212.NewRecordReader(os.Stdin, internal.NewOpenFIGI(&http.Client{Timeout: 5 * time.Second}))
|
||||
},
|
||||
}
|
||||
readerFactories = map[string]func() internal.RecordReader{
|
||||
"trading212": func() internal.RecordReader {
|
||||
return trading212.NewRecordReader(os.Stdin, internal.NewOpenFIGI(&http.Client{Timeout: 5 * time.Second}))
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func main() {
|
||||
pflag.Parse()
|
||||
|
||||
err := run(context.Background())
|
||||
if err != nil {
|
||||
slog.Error("found a fatal issue", slog.Any("err", err))
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func run(ctx context.Context) error {
|
||||
if platform == nil || len(*platform) == 0 {
|
||||
slog.Error("--platform flag is required")
|
||||
os.Exit(1)
|
||||
@@ -41,14 +52,6 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err := run(context.Background(), *platform, *lang)
|
||||
if err != nil {
|
||||
slog.Error("found a fatal issue", slog.Any("err", err))
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func run(ctx context.Context, platform, lang string) error {
|
||||
ctx, cancel := signal.NotifyContext(ctx, os.Kill, os.Interrupt)
|
||||
defer cancel()
|
||||
|
||||
@@ -56,25 +59,30 @@ func run(ctx context.Context, platform, lang string) error {
|
||||
|
||||
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, nil)))
|
||||
|
||||
factory, ok := readerFactories[platform]
|
||||
factory, ok := readerFactories[*platform]
|
||||
if !ok {
|
||||
return fmt.Errorf("unsupported platform: %s", platform)
|
||||
return fmt.Errorf("unsupported platform: %s", *platform)
|
||||
}
|
||||
|
||||
reader := factory()
|
||||
|
||||
writer := internal.NewAggregatorWriter()
|
||||
|
||||
selector, err := internal.ParseSelectors(*selectors)
|
||||
if err != nil {
|
||||
return fmt.Errorf("parsing selectors: %w", err)
|
||||
}
|
||||
|
||||
eg.Go(func() error {
|
||||
return internal.BuildReport(ctx, reader, writer)
|
||||
return internal.BuildReport(ctx, reader, writer, selector)
|
||||
})
|
||||
|
||||
err := eg.Wait()
|
||||
err = eg.Wait()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
loc, err := NewLocalizer(lang)
|
||||
loc, err := NewLocalizer(*lang)
|
||||
if err != nil {
|
||||
return fmt.Errorf("create localizer: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user