make sportflag type
This commit is contained in:
parent
05353ccec4
commit
8ee2ff3467
|
@ -27,28 +27,7 @@ import (
|
||||||
|
|
||||||
var date string
|
var date string
|
||||||
var team teamFlag
|
var team teamFlag
|
||||||
|
var sport sportFlag
|
||||||
var sport string
|
|
||||||
var sportIDs = map[string]statsapi.SportID{
|
|
||||||
"mlb": statsapi.MLB,
|
|
||||||
"aaa": statsapi.TripleA,
|
|
||||||
"aa": statsapi.DoubleA,
|
|
||||||
"higha": statsapi.HighA,
|
|
||||||
"a": statsapi.SingleA,
|
|
||||||
"rookie": statsapi.Rookie,
|
|
||||||
"winter": statsapi.Winter,
|
|
||||||
"milb": statsapi.MILB,
|
|
||||||
"indie": statsapi.Independent,
|
|
||||||
"negro": statsapi.Negro,
|
|
||||||
"kbo": statsapi.Korea,
|
|
||||||
"npb": statsapi.NPB,
|
|
||||||
"int": statsapi.International,
|
|
||||||
"int18u": statsapi.International18U,
|
|
||||||
"int16u": statsapi.International16U,
|
|
||||||
"intamateur": statsapi.InternationalAmateur,
|
|
||||||
"college": statsapi.College,
|
|
||||||
"hs": statsapi.HighSchool,
|
|
||||||
}
|
|
||||||
|
|
||||||
func schedule(cmd *cobra.Command, args []string) {
|
func schedule(cmd *cobra.Command, args []string) {
|
||||||
var teamId string
|
var teamId string
|
||||||
|
@ -60,9 +39,9 @@ func schedule(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
var sportId string
|
var sportId string
|
||||||
if sport == "" {
|
if sport == "" {
|
||||||
sportId = string(sport)
|
sportId = strconv.Itoa(int(statsapi.MLB))
|
||||||
} else {
|
} else {
|
||||||
sportId = strconv.Itoa(int(sportIDs[sport]))
|
sportId = strconv.Itoa(int(sportIDs[string(sport)]))
|
||||||
}
|
}
|
||||||
|
|
||||||
sched, err := statsapi.RequestSchedule(sportId, teamId, date)
|
sched, err := statsapi.RequestSchedule(sportId, teamId, date)
|
||||||
|
@ -95,5 +74,5 @@ func init() {
|
||||||
// is called directly, e.g.:
|
// is called directly, e.g.:
|
||||||
scheduleCmd.Flags().VarP(&team, "team", "t", "team to get schedule for")
|
scheduleCmd.Flags().VarP(&team, "team", "t", "team to get schedule for")
|
||||||
scheduleCmd.Flags().StringVarP(&date, "date", "d", "", "date to get schedule for (YYYY-MM-DD)")
|
scheduleCmd.Flags().StringVarP(&date, "date", "d", "", "date to get schedule for (YYYY-MM-DD)")
|
||||||
scheduleCmd.Flags().StringVarP(&sport, "sport", "s", "mlb", "sport to get schedule for")
|
scheduleCmd.Flags().VarP(&sport, "sport", "s", "sport to get schedule for")
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
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 (
|
||||||
|
"errors"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"scm.dairydemon.net/filifa/mlblive/cmd/internal/statsapi"
|
||||||
|
)
|
||||||
|
|
||||||
|
var sportIDs = map[string]statsapi.SportID{
|
||||||
|
"mlb": statsapi.MLB,
|
||||||
|
"aaa": statsapi.TripleA,
|
||||||
|
"aa": statsapi.DoubleA,
|
||||||
|
"higha": statsapi.HighA,
|
||||||
|
"a": statsapi.SingleA,
|
||||||
|
"rookie": statsapi.Rookie,
|
||||||
|
"winter": statsapi.Winter,
|
||||||
|
"milb": statsapi.MILB,
|
||||||
|
"indie": statsapi.Independent,
|
||||||
|
"negro": statsapi.Negro,
|
||||||
|
"kbo": statsapi.Korea,
|
||||||
|
"npb": statsapi.NPB,
|
||||||
|
"int": statsapi.International,
|
||||||
|
"int18u": statsapi.International18U,
|
||||||
|
"int16u": statsapi.International16U,
|
||||||
|
"intamateur": statsapi.InternationalAmateur,
|
||||||
|
"college": statsapi.College,
|
||||||
|
"hs": statsapi.HighSchool,
|
||||||
|
}
|
||||||
|
|
||||||
|
type sportFlag string
|
||||||
|
|
||||||
|
func (t *sportFlag) String() string {
|
||||||
|
return string(*t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *sportFlag) Set(v string) error {
|
||||||
|
var err error
|
||||||
|
v = strings.ToLower(v)
|
||||||
|
|
||||||
|
if v == "" {
|
||||||
|
*t = sportFlag(v)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
_, ok := sportIDs[v]
|
||||||
|
if !ok {
|
||||||
|
allowed := allowedFlags(sportIDs)
|
||||||
|
allowedList := strings.Join(allowed, ", ")
|
||||||
|
err = errors.New("sport must be one of " + allowedList)
|
||||||
|
} else {
|
||||||
|
*t = sportFlag(v)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *sportFlag) Type() string {
|
||||||
|
return "sportFlag"
|
||||||
|
}
|
Loading…
Reference in New Issue