make team flag optional

This commit is contained in:
filifa committed 2024-07-19 22:21:50 -05:00
1 parent 8051308692
commit 0ac209dda9
2 files changed
+14 -3

No files matched your search

+8 -3
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")
}
+6
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")