| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- // Package providers builds the store clients selected by a store name.
- //
- // It is shared by the CLI (cmd/cheapo) and the MCP server so both select
- // stores and regional settings the same way.
- package providers
- import (
- "fmt"
- "gogs.netdome.biz/paul/cheapo/internal/epic"
- "gogs.netdome.biz/paul/cheapo/internal/game"
- "gogs.netdome.biz/paul/cheapo/internal/gog"
- "gogs.netdome.biz/paul/cheapo/internal/steam"
- )
- // Names lists the accepted values of Options.Store.
- var Names = []string{"epic", "steam", "gog", "all"}
- // Options selects stores and regional settings.
- type Options struct {
- Store string // epic, steam, gog or all; empty means all
- Country string // ISO country code for Epic, empty keeps the client default
- Locale string // store locale for Epic, empty keeps the client default
- }
- // New returns the providers selected by opts.Store.
- func New(opts Options) ([]game.Provider, error) {
- newEpic := func() *epic.Client {
- c := epic.NewClient()
- if opts.Country != "" {
- c.Country = opts.Country
- }
- if opts.Locale != "" {
- c.Locale = opts.Locale
- }
- return c
- }
- switch opts.Store {
- case "epic":
- return []game.Provider{newEpic()}, nil
- case "steam":
- return []game.Provider{steam.NewClient()}, nil
- case "gog":
- return []game.Provider{gog.NewClient()}, nil
- case "", "all":
- return []game.Provider{newEpic(), steam.NewClient(), gog.NewClient()}, nil
- default:
- return nil, fmt.Errorf("unknown store %q (epic, steam, gog, all)", opts.Store)
- }
- }
|