mlbstats/cmd/leagueabbr.go

60 lines
1.2 KiB
Go
Raw Normal View History

2024-07-29 00:17:51 +00:00
/*
2025-04-07 03:06:31 +00:00
Copyright © 2024,2025 filifa
2024-07-29 00:17:51 +00:00
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cmd
import (
"strings"
)
2025-04-06 05:12:36 +00:00
// retrieved from https://statsapi.mlb.com/api/v1/leagues
2025-04-07 02:29:56 +00:00
var leagueIDs = map[string]int{
2025-04-06 05:07:57 +00:00
"al": 103,
"nl": 104,
"nn2": 431,
"nnl": 430,
"ewl": 429,
"nal": 428,
"ecl": 427,
"anl": 426,
"nsl": 432,
"aa": 100,
"pl": 105,
"ua": 101,
"fl": 106,
2024-07-29 00:26:53 +00:00
}
2024-07-29 05:21:51 +00:00
type leagueAbbr string
2024-07-29 00:17:51 +00:00
2024-07-29 05:21:51 +00:00
func (t *leagueAbbr) String() string {
2024-07-29 00:17:51 +00:00
return string(*t)
}
2024-07-29 05:21:51 +00:00
func (t *leagueAbbr) Set(v string) error {
2024-07-29 00:17:51 +00:00
v = strings.ToLower(v)
2024-07-29 04:32:50 +00:00
err := validateFlag(v, leagueIDs)
if err != nil {
return err
2024-07-29 00:17:51 +00:00
}
2024-07-29 04:32:50 +00:00
2024-07-29 05:21:51 +00:00
*t = leagueAbbr(v)
2024-07-29 04:32:50 +00:00
return nil
2024-07-29 00:17:51 +00:00
}
2024-07-29 05:21:51 +00:00
func (t *leagueAbbr) Type() string {
return "leagueAbbr"
2024-07-29 00:17:51 +00:00
}