create custom type for team flag
This commit is contained in:
@@ -28,14 +28,14 @@ import (
|
|||||||
"scm.dairydemon.net/filifa/mlblive/cmd/internal/statsapi"
|
"scm.dairydemon.net/filifa/mlblive/cmd/internal/statsapi"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Team string
|
var Team TeamFlag
|
||||||
|
|
||||||
func getGamePk() (string, error) {
|
func getGamePk() (string, error) {
|
||||||
if Team == "" {
|
if Team == "" {
|
||||||
return "", errors.New("need team ID")
|
return "", errors.New("need team ID")
|
||||||
}
|
}
|
||||||
|
|
||||||
id, ok := statsapi.TeamIds[Team]
|
id, ok := statsapi.TeamIds[string(Team)]
|
||||||
if !ok {
|
if !ok {
|
||||||
return "", errors.New("invalid team ID")
|
return "", errors.New("invalid team ID")
|
||||||
}
|
}
|
||||||
@@ -143,6 +143,6 @@ func init() {
|
|||||||
|
|
||||||
// Cobra also supports local flags, which will only run
|
// Cobra also supports local flags, which will only run
|
||||||
// when this action is called directly.
|
// when this action is called directly.
|
||||||
rootCmd.Flags().StringVarP(&Team, "team", "t", "", "team to get updates for")
|
rootCmd.Flags().VarP(&Team, "team", "t", "team to get updates for")
|
||||||
rootCmd.MarkFlagRequired("team")
|
rootCmd.MarkFlagRequired("team")
|
||||||
}
|
}
|
||||||
|
|||||||
23
cmd/teamflag.go
Normal file
23
cmd/teamflag.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
type TeamFlag string
|
||||||
|
|
||||||
|
func (t *TeamFlag) String() string {
|
||||||
|
return string(*t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TeamFlag) Set(v string) error {
|
||||||
|
switch v {
|
||||||
|
case "laa", "az", "bal", "bos", "chc", "cin", "cle", "col", "det", "hou", "kc", "lad", "wsh", "nym", "oak", "pit", "sd", "sea", "sf", "stl", "tb", "tex", "tor", "min", "phi", "atl", "cws", "mia", "nyy", "mil":
|
||||||
|
*t = TeamFlag(v)
|
||||||
|
return nil
|
||||||
|
default:
|
||||||
|
return errors.New("invalid team ID")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TeamFlag) Type() string {
|
||||||
|
return "team flag"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user