Fix selector behaviour #26

Merged
natercio merged 4 commits from fix-selector-behaviour into main 2026-07-11 15:24:54 +01:00
2 changed files with 6 additions and 5 deletions
Showing only changes of commit 9088f6bb14 - Show all commits
+3 -5
View File
@@ -25,7 +25,7 @@ var (
format = pflag.StringP("format", "f", "table", "Output format: table or csv") format = pflag.StringP("format", "f", "table", "Output format: table or csv")
ofAPIKey = pflag.String("open-figi-api-key", "", "An OpenFIGI API key for faster report generation (better rate api rate limits)") ofAPIKey = pflag.String("open-figi-api-key", "", "An OpenFIGI API key for faster report generation (better rate api rate limits)")
// TODO: improve documentation on selectors // TODO: improve documentation on selectors
selectors = pflag.StringSlice("selectors", nil, "Only process entries that conform to all the selectors:") selectors = pflag.StringSlice("selectors", nil, "Only process entries that conform to all the selectors: code, assetCountry")
) )
func main() { func main() {
@@ -51,13 +51,11 @@ func run(ctx context.Context) error {
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: logLevel}))) slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: logLevel})))
if platform == nil || len(*platform) == 0 { if platform == nil || len(*platform) == 0 {
slog.Error("--platform flag is required") return fmt.Errorf("--platform flag is required")
os.Exit(1)
} }
if lang == nil || len(*lang) == 0 { if lang == nil || len(*lang) == 0 {
slog.Error("--language flag is required") return fmt.Errorf("--language flag is required")
os.Exit(1)
} }
reader, err := getReader(*platform, *ofAPIKey) reader, err := getReader(*platform, *ofAPIKey)
+3
View File
@@ -16,12 +16,15 @@ func And(a, b Selector) Selector {
} }
} }
// OnlyNature will only select records with the given Nature n (G01, G20, etc...).
func OnlyNature(n Nature) Selector { func OnlyNature(n Nature) Selector {
return func(r Record) bool { return func(r Record) bool {
return r.Nature() == n return r.Nature() == n
} }
} }
// OnlyAssetCountry will only select records with the given ISO code c (620 for Portugal, 196 for
// Cyprus, etc...).
func OnlyAssetCountry(c int64) Selector { func OnlyAssetCountry(c int64) Selector {
return func(r Record) bool { return func(r Record) bool {
return r.AssetCountry() == c return r.AssetCountry() == c