mlbstats/cmd/teamabbr.go

77 lines
1.4 KiB
Go

/*
Copyright © 2024 filifa
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"
)
// retrieved from https://statsapi.mlb.com/api/v1/teams
var teamIDs = map[string]int32{
"laa": 108,
"az": 109,
"bal": 110,
"bos": 111,
"chc": 112,
"cin": 113,
"cle": 114,
"col": 115,
"det": 116,
"hou": 117,
"kc": 118,
"lad": 119,
"wsh": 120,
"nym": 121,
"oak": 133,
"pit": 134,
"sd": 135,
"sea": 136,
"sf": 137,
"stl": 138,
"tb": 139,
"tex": 140,
"tor": 141,
"min": 142,
"phi": 143,
"atl": 144,
"cws": 145,
"mia": 146,
"nyy": 147,
"mil": 158,
}
type teamAbbr string
func (t *teamAbbr) String() string {
return string(*t)
}
func (t *teamAbbr) Set(v string) error {
v = strings.ToLower(v)
err := validateFlag(v, teamIDs)
if err != nil {
return err
}
*t = teamAbbr(v)
return nil
}
func (t *teamAbbr) Type() string {
return "teamAbbr"
}