make team flag optional

This commit is contained in:
filifa 2024-07-19 22:14:09 -05:00
parent 8051308692
commit 0ac209dda9
2 changed files with 14 additions and 3 deletions

View File

@ -60,8 +60,14 @@ var teamIDs = map[string]statsapi.TeamID{
}
func schedule(cmd *cobra.Command, args []string) {
id := teamIDs[string(team)]
sched, err := statsapi.RequestSchedule("1", strconv.Itoa(int(id)))
var id string
if team == "" {
id = string(team)
} else {
id = strconv.Itoa(int(teamIDs[string(team)]))
}
sched, err := statsapi.RequestSchedule("1", id)
if err != nil {
log.Fatal(err)
}
@ -89,5 +95,4 @@ func init() {
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
scheduleCmd.Flags().VarP(&team, "team", "t", "team to get updates for (atl, az, bal, bos, chc, cin, cle, col, cws, det, hou, kc, laa, lad, mia, mil, min, nym, nyy, oak, phi, pit, sd, sea, sf, stl, tb, tex, tor, wsh)")
scheduleCmd.MarkFlagRequired("team")
}

View File

@ -29,6 +29,12 @@ func (t *teamFlag) String() string {
func (t *teamFlag) Set(v string) error {
var err error
v = strings.ToLower(v)
if v == "" {
*t = teamFlag(v)
return nil
}
_, ok := teamIDs[v]
if !ok {
err = errors.New("invalid team ID")