make team flag optional
This commit is contained in:
1 parent
8051308692
commit
0ac209dda9
2 files changed
+14
-3
No files matched your search
+8
-3
@@ -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")
|
||||
}
|
||||
@@ -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")
|
||||
|
||||
Reference in new issue
Block a user