-
Notifications
You must be signed in to change notification settings - Fork 0
/
draft.go
121 lines (100 loc) · 2.82 KB
/
draft.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package main
import (
"log"
"os"
"os/signal"
"strings"
"github.com/davidnix/ffdraft/command"
"github.com/davidnix/ffdraft/players"
"github.com/fatih/color"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
)
var draftCmd = &cli.Command{
Name: "draft",
Usage: "Start interactive draft",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "csv",
Usage: "(required) path to projections csv",
Required: true,
},
},
Action: interactiveAction,
}
const draftUsage = `
--------------------------------------------------------------------------------------------------------------------
Commands:
ceil: print the highest ceiling value for available players for each position
exit, ctl+D: exits this program
find, f [name]: fuzzy finds players matching player name
floor, fl: print the highest floor value for available players for each position
help, h: print this help text
keep: remove a player without advancing draft position (useful for keeper leagues)
pick, p [name]: removes player from draft pool
position, dp: print current draft position
depth: print a team's depth chart
unpick, u [name]: adds player back to draft pool
--------------------------------------------------------------------------------------------------------------------`
func interactiveAction(ctx *cli.Context) error {
repo, err := buildRepo(ctx.String("csv"))
if err != nil {
return err
}
log.Println("Welcome to fantasy football!")
color.HiGreen("Loaded %d offensive players", len(repo.Available))
command.Floor(repo, []string{}, 30)
preventSigTerm()
return startInteractive(repo)
}
func preventSigTerm() {
ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Interrupt)
go func() {
for range ch {
log.Println("Interrupt caught: ignoring. Use `exit` or ctl+D")
}
}()
}
func startInteractive(repo *players.Repo) error {
log.Println(draftUsage)
for {
in, err := command.GetInput()
if err != nil {
return err
}
input := strings.Fields(in)
var cmd string
var args []string
if len(input) > 0 {
cmd = input[0]
args = input[1:]
}
switch cmd {
case "find", "f":
command.Find(repo, args)
case "pick", "p":
command.Pick(repo, args)
case "unpick", "u":
command.UnPick(repo, args)
case "keep":
command.Keep(repo, args)
case "floor", "fl":
command.Floor(repo, args, 30)
case "ceil":
command.Ceil(repo, args, 30)
case "depth":
command.DepthChart(repo, args)
case "position", "dp":
command.DraftPosition(repo)
case "help", "h", "usage":
log.Println(draftUsage)
case "exit":
return errors.New("user canceled")
case "":
continue
default:
log.Printf("Unrecognized command %q. Type help for usage.\n", cmd)
}
}
}