mlbstats/cmd/teamabbr.go

77 lines
1.4 KiB
Go
Raw Normal View History

2024-07-15 00:29:19 +00:00
/*
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/>.
*/
2024-07-14 23:05:07 +00:00
package cmd
2024-07-14 23:12:24 +00:00
import (
2024-07-15 00:14:56 +00:00
"strings"
2024-07-14 23:12:24 +00:00
)
2024-07-14 23:05:07 +00:00
2025-04-06 05:12:36 +00:00
// retrieved from https://statsapi.mlb.com/api/v1/teams
2025-04-06 05:07:57 +00:00
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,
2024-07-29 00:26:53 +00:00
}
2024-07-29 05:21:51 +00:00
type teamAbbr string
2024-07-14 23:05:07 +00:00
2024-07-29 05:21:51 +00:00
func (t *teamAbbr) String() string {
2024-07-14 23:05:07 +00:00
return string(*t)
}
2024-07-29 05:21:51 +00:00
func (t *teamAbbr) Set(v string) error {
2024-07-15 00:14:56 +00:00
v = strings.ToLower(v)
2024-07-20 03:14:09 +00:00
2024-07-29 04:32:50 +00:00
err := validateFlag(v, teamIDs)
if err != nil {
return err
2024-07-14 23:05:07 +00:00
}
2024-07-29 04:32:50 +00:00
2024-07-29 05:21:51 +00:00
*t = teamAbbr(v)
2024-07-29 04:32:50 +00:00
return nil
2024-07-14 23:05:07 +00:00
}
2024-07-29 05:21:51 +00:00
func (t *teamAbbr) Type() string {
return "teamAbbr"
2024-07-14 23:05:07 +00:00
}