-
Notifications
You must be signed in to change notification settings - Fork 0
/
pickers.go
140 lines (126 loc) · 4.52 KB
/
pickers.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package main
import (
"context"
"time"
fs "cloud.google.com/go/firestore"
"github.com/reallyasi9/b1gpickem/internal/firestore"
"github.com/reallyasi9/b1gpickem/internal/tools/editpickers"
)
type addPickersCmd struct {
DryRun bool `help:"Print database writes to log and exit without writing."`
Pickers []firestore.Picker `arg:"" help:"Pickers to add. Must be strings in LukeName[:FullName[:JoinDate]] format." required:""`
}
func (a *addPickersCmd) Run(g *globalCmd) error {
ctx := editpickers.NewContext(context.Background())
ctx.DryRun = a.DryRun
var err error
ctx.FirestoreClient, err = fs.NewClient(ctx.Context, g.ProjectID)
if err != nil {
return err
}
ctx.Pickers = a.Pickers
return editpickers.AddPickers(ctx)
}
type rmPickersCmd struct {
Force bool `help:"Force overwriting or deleting data in database." xor:"Force,DryRun"`
DryRun bool `help:"Print database writes to log and exit without writing." xor:"Force,DryRun"`
KeepSeasons bool `help:"Keep removed pickers active in seasons. WARNING: Specifying this option will leave undefined references in the database!"`
Pickers []string `arg:"" help:"LukeNames of pickers to remove." required:""`
}
func (a *rmPickersCmd) Run(g *globalCmd) error {
ctx := editpickers.NewContext(context.Background())
ctx.DryRun = a.DryRun
ctx.Force = a.Force
var err error
ctx.FirestoreClient, err = fs.NewClient(ctx.Context, g.ProjectID)
if err != nil {
return err
}
pickers := make([]firestore.Picker, len(a.Pickers))
for i, picker := range a.Pickers {
pickers[i] = firestore.Picker{LukeName: picker}
}
ctx.Pickers = pickers
return editpickers.RmPickers(ctx)
}
type lsPickersCmd struct{}
func (a *lsPickersCmd) Run(g *globalCmd) error {
ctx := editpickers.NewContext(context.Background())
var err error
ctx.FirestoreClient, err = fs.NewClient(ctx.Context, g.ProjectID)
if err != nil {
return err
}
return editpickers.LsPickers(ctx)
}
type editPickerCmd struct {
Force bool `help:"Force overwriting or deleting data in database." xor:"Force,DryRun"`
DryRun bool `help:"Print database writes to log and exit without writing." xor:"Force,DryRun"`
KeepSeasons bool `help:"Do not update active pickers in seasons if LukeName changes. WARNING: Specifying this option will leave undefined references in the database!"`
ID string `arg:"" help:"Database ID of picker to edit." required:""`
LukeName string `help:"New LukeName for picker."`
Name string `help:"New Name for picker."`
JoinDate time.Time `help:"New JoinDate for picker." format:"2006/01/02"`
}
func (a *editPickerCmd) Run(g *globalCmd) error {
ctx := editpickers.NewContext(context.Background())
ctx.DryRun = a.DryRun
ctx.Force = a.Force
var err error
ctx.FirestoreClient, err = fs.NewClient(ctx.Context, g.ProjectID)
if err != nil {
return err
}
pickers := []firestore.Picker{
{
LukeName: a.LukeName,
Name: a.Name,
Joined: a.JoinDate,
},
}
ctx.Pickers = pickers
ctx.ID = a.ID
return editpickers.EditPicker(ctx)
}
type activatePickersCmd struct {
DryRun bool `help:"Print database writes to log and exit without writing."`
Season int `arg:"" help:"Season in which to activate pickers" required:""`
Pickers []string `arg:"" help:"LukeNames of pickers to activate." required:""`
}
func (a *activatePickersCmd) Run(g *globalCmd) error {
ctx := editpickers.NewContext(context.Background())
ctx.DryRun = a.DryRun
var err error
ctx.FirestoreClient, err = fs.NewClient(ctx.Context, g.ProjectID)
if err != nil {
return err
}
pickers := make([]firestore.Picker, len(a.Pickers))
for i, picker := range a.Pickers {
pickers[i] = firestore.Picker{LukeName: picker}
}
ctx.Pickers = pickers
ctx.Season = a.Season
return editpickers.ActivatePickers(ctx)
}
type deactivatePickersCmd struct {
DryRun bool `help:"Print database writes to log and exit without writing."`
Season int `arg:"" help:"Season from which to deactivate pickers" required:""`
Pickers []string `arg:"" help:"LukeNames of pickers to deactivate." required:""`
}
func (a *deactivatePickersCmd) Run(g *globalCmd) error {
ctx := editpickers.NewContext(context.Background())
ctx.DryRun = a.DryRun
var err error
ctx.FirestoreClient, err = fs.NewClient(ctx.Context, g.ProjectID)
if err != nil {
return err
}
pickers := make([]firestore.Picker, len(a.Pickers))
for i, picker := range a.Pickers {
pickers[i] = firestore.Picker{LukeName: picker}
}
ctx.Pickers = pickers
ctx.Season = a.Season
return editpickers.DeactivatePickers(ctx)
}