cricinfo-cli-go 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +63 -0
- package/CONTRIBUTORS.md +75 -0
- package/LICENSE +21 -0
- package/Makefile +131 -0
- package/README.md +130 -0
- package/bin/cricinfo.js +44 -0
- package/cmd/cricinfo/main.go +15 -0
- package/go.mod +10 -0
- package/go.sum +10 -0
- package/internal/app/app.go +11 -0
- package/internal/app/app_test.go +122 -0
- package/internal/buildinfo/buildinfo.go +16 -0
- package/internal/cli/analysis.go +262 -0
- package/internal/cli/analysis_test.go +175 -0
- package/internal/cli/competitions.go +154 -0
- package/internal/cli/competitions_test.go +165 -0
- package/internal/cli/leagues.go +297 -0
- package/internal/cli/leagues_test.go +194 -0
- package/internal/cli/matches.go +403 -0
- package/internal/cli/matches_test.go +413 -0
- package/internal/cli/players.go +263 -0
- package/internal/cli/players_test.go +384 -0
- package/internal/cli/root.go +141 -0
- package/internal/cli/search.go +119 -0
- package/internal/cli/teams.go +214 -0
- package/internal/cli/teams_test.go +192 -0
- package/internal/cricinfo/analysis.go +1401 -0
- package/internal/cricinfo/analysis_phase15_test.go +267 -0
- package/internal/cricinfo/client.go +471 -0
- package/internal/cricinfo/client_test.go +280 -0
- package/internal/cricinfo/cmd/fixture-refresh/main.go +145 -0
- package/internal/cricinfo/competitions.go +405 -0
- package/internal/cricinfo/competitions_phase13_test.go +234 -0
- package/internal/cricinfo/coverage_ledger.go +122 -0
- package/internal/cricinfo/coverage_ledger_test.go +253 -0
- package/internal/cricinfo/decode.go +115 -0
- package/internal/cricinfo/decode_test.go +100 -0
- package/internal/cricinfo/entity_index.go +618 -0
- package/internal/cricinfo/entity_index_test.go +175 -0
- package/internal/cricinfo/fixture_matrix.go +243 -0
- package/internal/cricinfo/fixture_matrix_test.go +49 -0
- package/internal/cricinfo/fixtures_test.go +264 -0
- package/internal/cricinfo/historical_hydration.go +1641 -0
- package/internal/cricinfo/historical_phase14_test.go +542 -0
- package/internal/cricinfo/leagues.go +1210 -0
- package/internal/cricinfo/leagues_phase12_test.go +324 -0
- package/internal/cricinfo/live_leagues_test.go +169 -0
- package/internal/cricinfo/live_matches_test.go +203 -0
- package/internal/cricinfo/live_matrix_test.go +118 -0
- package/internal/cricinfo/live_players_test.go +122 -0
- package/internal/cricinfo/live_search_test.go +86 -0
- package/internal/cricinfo/live_smoke_test.go +213 -0
- package/internal/cricinfo/live_teams_test.go +104 -0
- package/internal/cricinfo/matches.go +1508 -0
- package/internal/cricinfo/matches_phase7_test.go +207 -0
- package/internal/cricinfo/matches_phase9_test.go +253 -0
- package/internal/cricinfo/normalize_entities.go +1727 -0
- package/internal/cricinfo/normalize_leagues.go +346 -0
- package/internal/cricinfo/players.go +1332 -0
- package/internal/cricinfo/players_phase10_test.go +174 -0
- package/internal/cricinfo/players_phase11_test.go +373 -0
- package/internal/cricinfo/render_contract.go +1088 -0
- package/internal/cricinfo/render_phase4_test.go +633 -0
- package/internal/cricinfo/renderer.go +1689 -0
- package/internal/cricinfo/resolver.go +813 -0
- package/internal/cricinfo/resolver_test.go +244 -0
- package/internal/cricinfo/teams.go +603 -0
- package/internal/cricinfo/teams_phase8_test.go +231 -0
- package/internal/cricinfo/testdata/fixtures/README.md +43 -0
- package/internal/cricinfo/testdata/fixtures/aux-competition-metadata/broadcasts.json +11 -0
- package/internal/cricinfo/testdata/fixtures/aux-competition-metadata/officials.json +150 -0
- package/internal/cricinfo/testdata/fixtures/details-plays/detail-110.json +157 -0
- package/internal/cricinfo/testdata/fixtures/details-plays/detail-52545007.json +145 -0
- package/internal/cricinfo/testdata/fixtures/details-plays/detail-52559021.json +143 -0
- package/internal/cricinfo/testdata/fixtures/details-plays/plays.json +15 -0
- package/internal/cricinfo/testdata/fixtures/endpoint-matrix.tsv +19 -0
- package/internal/cricinfo/testdata/fixtures/innings-fow-partnerships/fow-1.json +12 -0
- package/internal/cricinfo/testdata/fixtures/innings-fow-partnerships/fow.json +42 -0
- package/internal/cricinfo/testdata/fixtures/innings-fow-partnerships/innings-1-2.json +38 -0
- package/internal/cricinfo/testdata/fixtures/innings-fow-partnerships/partnership-1.json +31 -0
- package/internal/cricinfo/testdata/fixtures/innings-fow-partnerships/partnerships.json +42 -0
- package/internal/cricinfo/testdata/fixtures/leagues-seasons-standings/calendar-offdays.json +20 -0
- package/internal/cricinfo/testdata/fixtures/leagues-seasons-standings/calendar-ondays.json +21 -0
- package/internal/cricinfo/testdata/fixtures/leagues-seasons-standings/calendar.json +14 -0
- package/internal/cricinfo/testdata/fixtures/leagues-seasons-standings/season-2025.json +13 -0
- package/internal/cricinfo/testdata/fixtures/leagues-seasons-standings/season-group-1.json +13 -0
- package/internal/cricinfo/testdata/fixtures/leagues-seasons-standings/season-groups.json +11 -0
- package/internal/cricinfo/testdata/fixtures/leagues-seasons-standings/season-type-1.json +13 -0
- package/internal/cricinfo/testdata/fixtures/leagues-seasons-standings/season-types.json +11 -0
- package/internal/cricinfo/testdata/fixtures/leagues-seasons-standings/seasons.json +30 -0
- package/internal/cricinfo/testdata/fixtures/leagues-seasons-standings/standings-item-1.json +72 -0
- package/internal/cricinfo/testdata/fixtures/leagues-seasons-standings/standings-root.json +3 -0
- package/internal/cricinfo/testdata/fixtures/leagues-seasons-standings/standings.json +15 -0
- package/internal/cricinfo/testdata/fixtures/matches-competitions/competition.json +460 -0
- package/internal/cricinfo/testdata/fixtures/matches-competitions/event-1529474.json +86 -0
- package/internal/cricinfo/testdata/fixtures/matches-competitions/matchcards-1527966.json +368 -0
- package/internal/cricinfo/testdata/fixtures/matches-competitions/situation-1529474.json +10 -0
- package/internal/cricinfo/testdata/fixtures/players/athlete-1361257-statistics.json +126 -0
- package/internal/cricinfo/testdata/fixtures/players/athlete-1361257.json +113 -0
- package/internal/cricinfo/testdata/fixtures/players/roster-1361257-linescores-1-1-statistics-0.json +208 -0
- package/internal/cricinfo/testdata/fixtures/players/roster-1361257-linescores-1-2-statistics-0.json +252 -0
- package/internal/cricinfo/testdata/fixtures/players/roster-1361257-linescores.json +74 -0
- package/internal/cricinfo/testdata/fixtures/players/roster-1361257-statistics-0.json +1008 -0
- package/internal/cricinfo/testdata/fixtures/root-discovery/events.json +72 -0
- package/internal/cricinfo/testdata/fixtures/root-discovery/root.json +28 -0
- package/internal/cricinfo/testdata/fixtures/team-competitor/competitor-789643.json +40 -0
- package/internal/cricinfo/testdata/fixtures/team-competitor/leaders-789643.json +353 -0
- package/internal/cricinfo/testdata/fixtures/team-competitor/records-789643.json +91 -0
- package/internal/cricinfo/testdata/fixtures/team-competitor/roster-1147772-object.json +231 -0
- package/internal/cricinfo/testdata/fixtures/team-competitor/roster-1147772.json +235 -0
- package/internal/cricinfo/testdata/fixtures/team-competitor/roster-789643.json +322 -0
- package/internal/cricinfo/testdata/fixtures/team-competitor/scores-789643.json +19 -0
- package/internal/cricinfo/testdata/fixtures/team-competitor/statistics-789643.json +629 -0
- package/internal/cricinfo/testdata/fixtures/team-competitor/team-789643-athletes.json +7 -0
- package/internal/cricinfo/testdata/fixtures/team-competitor/team-789643.json +67 -0
- package/internal/cricinfo/testdata/golden/match-empty.golden +1 -0
- package/internal/cricinfo/testdata/golden/match-list.golden +2 -0
- package/internal/cricinfo/testdata/golden/match-partial.golden +3 -0
- package/internal/cricinfo/types.go +54 -0
- package/package.json +51 -0
- package/scripts/postinstall.js +153 -0
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
package cli
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"fmt"
|
|
6
|
+
"strings"
|
|
7
|
+
|
|
8
|
+
"github.com/amxv/cricinfo-cli/internal/cricinfo"
|
|
9
|
+
"github.com/spf13/cobra"
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
type matchCommandService interface {
|
|
13
|
+
Close() error
|
|
14
|
+
List(ctx context.Context, opts cricinfo.MatchListOptions) (cricinfo.NormalizedResult, error)
|
|
15
|
+
Live(ctx context.Context, opts cricinfo.MatchListOptions) (cricinfo.NormalizedResult, error)
|
|
16
|
+
Show(ctx context.Context, query string, opts cricinfo.MatchLookupOptions) (cricinfo.NormalizedResult, error)
|
|
17
|
+
Status(ctx context.Context, query string, opts cricinfo.MatchLookupOptions) (cricinfo.NormalizedResult, error)
|
|
18
|
+
Scorecard(ctx context.Context, query string, opts cricinfo.MatchLookupOptions) (cricinfo.NormalizedResult, error)
|
|
19
|
+
Details(ctx context.Context, query string, opts cricinfo.MatchLookupOptions) (cricinfo.NormalizedResult, error)
|
|
20
|
+
Plays(ctx context.Context, query string, opts cricinfo.MatchLookupOptions) (cricinfo.NormalizedResult, error)
|
|
21
|
+
Situation(ctx context.Context, query string, opts cricinfo.MatchLookupOptions) (cricinfo.NormalizedResult, error)
|
|
22
|
+
Innings(ctx context.Context, query string, opts cricinfo.MatchInningsOptions) (cricinfo.NormalizedResult, error)
|
|
23
|
+
Partnerships(ctx context.Context, query string, opts cricinfo.MatchInningsOptions) (cricinfo.NormalizedResult, error)
|
|
24
|
+
FallOfWicket(ctx context.Context, query string, opts cricinfo.MatchInningsOptions) (cricinfo.NormalizedResult, error)
|
|
25
|
+
Deliveries(ctx context.Context, query string, opts cricinfo.MatchInningsOptions) (cricinfo.NormalizedResult, error)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type matchRuntimeOptions struct {
|
|
29
|
+
limit int
|
|
30
|
+
leagueID string
|
|
31
|
+
team string
|
|
32
|
+
innings int
|
|
33
|
+
period int
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
var newMatchService = func() (matchCommandService, error) {
|
|
37
|
+
return cricinfo.NewMatchService(cricinfo.MatchServiceConfig{})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
func newMatchesCommand(global *globalOptions) *cobra.Command {
|
|
41
|
+
opts := &matchRuntimeOptions{}
|
|
42
|
+
|
|
43
|
+
cmd := &cobra.Command{
|
|
44
|
+
Use: "matches",
|
|
45
|
+
Short: "Live and current match discovery with status and summary views.",
|
|
46
|
+
Long: strings.Join([]string{
|
|
47
|
+
"Discover current matches from Cricinfo events and inspect normalized match summaries.",
|
|
48
|
+
"",
|
|
49
|
+
"Next steps:",
|
|
50
|
+
" cricinfo matches live",
|
|
51
|
+
" cricinfo matches list",
|
|
52
|
+
" cricinfo matches show <match>",
|
|
53
|
+
" cricinfo matches status <match>",
|
|
54
|
+
" cricinfo matches scorecard <match>",
|
|
55
|
+
" cricinfo matches innings <match>",
|
|
56
|
+
}, "\n"),
|
|
57
|
+
Args: cobra.NoArgs,
|
|
58
|
+
RunE: func(cmd *cobra.Command, _ []string) error {
|
|
59
|
+
return cmd.Help()
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
cmd.PersistentFlags().StringVar(&opts.leagueID, "league", "", "Preferred league ID for match resolution context")
|
|
64
|
+
|
|
65
|
+
listCmd := &cobra.Command{
|
|
66
|
+
Use: "list",
|
|
67
|
+
Short: "List current matches from /events",
|
|
68
|
+
Long: strings.Join([]string{
|
|
69
|
+
"Traverse current events and list normalized matches with teams, state, date, venue, and score summary.",
|
|
70
|
+
"",
|
|
71
|
+
"Next steps:",
|
|
72
|
+
" cricinfo matches show <match>",
|
|
73
|
+
" cricinfo matches status <match>",
|
|
74
|
+
" cricinfo matches scorecard <match>",
|
|
75
|
+
" cricinfo matches innings <match>",
|
|
76
|
+
}, "\n"),
|
|
77
|
+
Args: cobra.NoArgs,
|
|
78
|
+
RunE: func(cmd *cobra.Command, _ []string) error {
|
|
79
|
+
return runMatchCommand(cmd, global, func(ctx context.Context, service matchCommandService) (cricinfo.NormalizedResult, error) {
|
|
80
|
+
return service.List(ctx, cricinfo.MatchListOptions{Limit: opts.limit})
|
|
81
|
+
})
|
|
82
|
+
},
|
|
83
|
+
}
|
|
84
|
+
listCmd.Flags().IntVar(&opts.limit, "limit", 20, "Maximum number of matches to return")
|
|
85
|
+
|
|
86
|
+
liveCmd := &cobra.Command{
|
|
87
|
+
Use: "live",
|
|
88
|
+
Short: "List current live matches from /events",
|
|
89
|
+
Long: strings.Join([]string{
|
|
90
|
+
"Traverse current events and return only in-progress live matches.",
|
|
91
|
+
"",
|
|
92
|
+
"Next steps:",
|
|
93
|
+
" cricinfo matches show <match>",
|
|
94
|
+
" cricinfo matches status <match>",
|
|
95
|
+
" cricinfo matches scorecard <match>",
|
|
96
|
+
" cricinfo matches innings <match>",
|
|
97
|
+
}, "\n"),
|
|
98
|
+
Args: cobra.NoArgs,
|
|
99
|
+
RunE: func(cmd *cobra.Command, _ []string) error {
|
|
100
|
+
return runMatchCommand(cmd, global, func(ctx context.Context, service matchCommandService) (cricinfo.NormalizedResult, error) {
|
|
101
|
+
return service.Live(ctx, cricinfo.MatchListOptions{Limit: opts.limit})
|
|
102
|
+
})
|
|
103
|
+
},
|
|
104
|
+
}
|
|
105
|
+
liveCmd.Flags().IntVar(&opts.limit, "limit", 20, "Maximum number of live matches to return")
|
|
106
|
+
|
|
107
|
+
showCmd := &cobra.Command{
|
|
108
|
+
Use: "show <match>",
|
|
109
|
+
Short: "Show one match summary",
|
|
110
|
+
Long: strings.Join([]string{
|
|
111
|
+
"Resolve a match by ID/ref/alias and show the normalized summary with teams, state, date, venue, and scores.",
|
|
112
|
+
"",
|
|
113
|
+
"Next steps:",
|
|
114
|
+
" cricinfo matches status <match>",
|
|
115
|
+
" cricinfo matches scorecard <match>",
|
|
116
|
+
" cricinfo matches innings <match>",
|
|
117
|
+
}, "\n"),
|
|
118
|
+
Args: cobra.MinimumNArgs(1),
|
|
119
|
+
RunE: func(cmd *cobra.Command, args []string) error {
|
|
120
|
+
query := strings.TrimSpace(strings.Join(args, " "))
|
|
121
|
+
return runMatchCommand(cmd, global, func(ctx context.Context, service matchCommandService) (cricinfo.NormalizedResult, error) {
|
|
122
|
+
return service.Show(ctx, query, cricinfo.MatchLookupOptions{LeagueID: opts.leagueID})
|
|
123
|
+
})
|
|
124
|
+
},
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
statusCmd := &cobra.Command{
|
|
128
|
+
Use: "status <match>",
|
|
129
|
+
Short: "Show one match status",
|
|
130
|
+
Long: strings.Join([]string{
|
|
131
|
+
"Resolve a match by ID/ref/alias and show the current match status summary.",
|
|
132
|
+
"",
|
|
133
|
+
"Next steps:",
|
|
134
|
+
" cricinfo matches show <match>",
|
|
135
|
+
" cricinfo matches scorecard <match>",
|
|
136
|
+
" cricinfo matches innings <match>",
|
|
137
|
+
}, "\n"),
|
|
138
|
+
Args: cobra.MinimumNArgs(1),
|
|
139
|
+
RunE: func(cmd *cobra.Command, args []string) error {
|
|
140
|
+
query := strings.TrimSpace(strings.Join(args, " "))
|
|
141
|
+
return runMatchCommand(cmd, global, func(ctx context.Context, service matchCommandService) (cricinfo.NormalizedResult, error) {
|
|
142
|
+
return service.Status(ctx, query, cricinfo.MatchLookupOptions{LeagueID: opts.leagueID})
|
|
143
|
+
})
|
|
144
|
+
},
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
scorecardCmd := &cobra.Command{
|
|
148
|
+
Use: "scorecard <match>",
|
|
149
|
+
Short: "Show batting, bowling, and partnerships scorecards for one match",
|
|
150
|
+
Long: strings.Join([]string{
|
|
151
|
+
"Resolve a match and render normalized batting, bowling, and partnerships scorecard views.",
|
|
152
|
+
"",
|
|
153
|
+
"Next steps:",
|
|
154
|
+
" cricinfo matches details <match>",
|
|
155
|
+
" cricinfo matches plays <match>",
|
|
156
|
+
" cricinfo matches situation <match>",
|
|
157
|
+
}, "\n"),
|
|
158
|
+
Args: cobra.MinimumNArgs(1),
|
|
159
|
+
RunE: func(cmd *cobra.Command, args []string) error {
|
|
160
|
+
query := strings.TrimSpace(strings.Join(args, " "))
|
|
161
|
+
return runMatchCommand(cmd, global, func(ctx context.Context, service matchCommandService) (cricinfo.NormalizedResult, error) {
|
|
162
|
+
return service.Scorecard(ctx, query, cricinfo.MatchLookupOptions{LeagueID: opts.leagueID})
|
|
163
|
+
})
|
|
164
|
+
},
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
detailsCmd := &cobra.Command{
|
|
168
|
+
Use: "details <match>",
|
|
169
|
+
Short: "Show normalized delivery events from match details",
|
|
170
|
+
Long: strings.Join([]string{
|
|
171
|
+
"Resolve a match and render normalized detail delivery events with batsman/bowler refs, score value, dismissal, and over context.",
|
|
172
|
+
"",
|
|
173
|
+
"Next steps:",
|
|
174
|
+
" cricinfo matches plays <match>",
|
|
175
|
+
" cricinfo matches scorecard <match>",
|
|
176
|
+
" cricinfo matches situation <match>",
|
|
177
|
+
}, "\n"),
|
|
178
|
+
Args: cobra.MinimumNArgs(1),
|
|
179
|
+
RunE: func(cmd *cobra.Command, args []string) error {
|
|
180
|
+
query := strings.TrimSpace(strings.Join(args, " "))
|
|
181
|
+
return runMatchCommand(cmd, global, func(ctx context.Context, service matchCommandService) (cricinfo.NormalizedResult, error) {
|
|
182
|
+
return service.Details(ctx, query, cricinfo.MatchLookupOptions{LeagueID: opts.leagueID})
|
|
183
|
+
})
|
|
184
|
+
},
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
playsCmd := &cobra.Command{
|
|
188
|
+
Use: "plays <match>",
|
|
189
|
+
Short: "Show normalized delivery events from match plays",
|
|
190
|
+
Long: strings.Join([]string{
|
|
191
|
+
"Resolve a match and render normalized play delivery events.",
|
|
192
|
+
"",
|
|
193
|
+
"Next steps:",
|
|
194
|
+
" cricinfo matches details <match>",
|
|
195
|
+
" cricinfo matches scorecard <match>",
|
|
196
|
+
" cricinfo matches situation <match>",
|
|
197
|
+
}, "\n"),
|
|
198
|
+
Args: cobra.MinimumNArgs(1),
|
|
199
|
+
RunE: func(cmd *cobra.Command, args []string) error {
|
|
200
|
+
query := strings.TrimSpace(strings.Join(args, " "))
|
|
201
|
+
return runMatchCommand(cmd, global, func(ctx context.Context, service matchCommandService) (cricinfo.NormalizedResult, error) {
|
|
202
|
+
return service.Plays(ctx, query, cricinfo.MatchLookupOptions{LeagueID: opts.leagueID})
|
|
203
|
+
})
|
|
204
|
+
},
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
situationCmd := &cobra.Command{
|
|
208
|
+
Use: "situation <match>",
|
|
209
|
+
Short: "Show match situation data when available",
|
|
210
|
+
Long: strings.Join([]string{
|
|
211
|
+
"Resolve a match and render normalized situation data. Sparse situation payloads are treated as valid empty results.",
|
|
212
|
+
"",
|
|
213
|
+
"Next steps:",
|
|
214
|
+
" cricinfo matches status <match>",
|
|
215
|
+
" cricinfo matches details <match>",
|
|
216
|
+
" cricinfo matches scorecard <match>",
|
|
217
|
+
}, "\n"),
|
|
218
|
+
Args: cobra.MinimumNArgs(1),
|
|
219
|
+
RunE: func(cmd *cobra.Command, args []string) error {
|
|
220
|
+
query := strings.TrimSpace(strings.Join(args, " "))
|
|
221
|
+
return runMatchCommand(cmd, global, func(ctx context.Context, service matchCommandService) (cricinfo.NormalizedResult, error) {
|
|
222
|
+
return service.Situation(ctx, query, cricinfo.MatchLookupOptions{LeagueID: opts.leagueID})
|
|
223
|
+
})
|
|
224
|
+
},
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
inningsCmd := &cobra.Command{
|
|
228
|
+
Use: "innings <match>",
|
|
229
|
+
Short: "Show innings summaries with over and wicket timelines",
|
|
230
|
+
Long: strings.Join([]string{
|
|
231
|
+
"Resolve a match and return normalized innings summaries.",
|
|
232
|
+
"Use --team to focus on one team competitor.",
|
|
233
|
+
"",
|
|
234
|
+
"Next steps:",
|
|
235
|
+
" cricinfo matches partnerships <match> --team <team> --innings <n> --period <n>",
|
|
236
|
+
" cricinfo matches fow <match> --team <team> --innings <n> --period <n>",
|
|
237
|
+
" cricinfo matches deliveries <match> --team <team> --innings <n> --period <n>",
|
|
238
|
+
}, "\n"),
|
|
239
|
+
Args: cobra.MinimumNArgs(1),
|
|
240
|
+
RunE: func(cmd *cobra.Command, args []string) error {
|
|
241
|
+
query := strings.TrimSpace(strings.Join(args, " "))
|
|
242
|
+
return runMatchCommand(cmd, global, func(ctx context.Context, service matchCommandService) (cricinfo.NormalizedResult, error) {
|
|
243
|
+
return service.Innings(ctx, query, cricinfo.MatchInningsOptions{
|
|
244
|
+
LeagueID: opts.leagueID,
|
|
245
|
+
TeamQuery: opts.team,
|
|
246
|
+
})
|
|
247
|
+
})
|
|
248
|
+
},
|
|
249
|
+
}
|
|
250
|
+
inningsCmd.Flags().StringVar(&opts.team, "team", "", "Optional: team ID/ref/alias to scope innings")
|
|
251
|
+
|
|
252
|
+
partnershipsCmd := &cobra.Command{
|
|
253
|
+
Use: "partnerships <match>",
|
|
254
|
+
Short: "Show partnerships for a selected team innings period",
|
|
255
|
+
Long: strings.Join([]string{
|
|
256
|
+
"Resolve one match and team, select innings/period, and render detailed partnership objects.",
|
|
257
|
+
"",
|
|
258
|
+
"Required flags:",
|
|
259
|
+
" --team <team>",
|
|
260
|
+
" --innings <n>",
|
|
261
|
+
" --period <n>",
|
|
262
|
+
}, "\n"),
|
|
263
|
+
Args: cobra.MinimumNArgs(1),
|
|
264
|
+
RunE: func(cmd *cobra.Command, args []string) error {
|
|
265
|
+
if strings.TrimSpace(opts.team) == "" {
|
|
266
|
+
return fmt.Errorf("--team is required")
|
|
267
|
+
}
|
|
268
|
+
if opts.innings <= 0 {
|
|
269
|
+
return fmt.Errorf("--innings is required")
|
|
270
|
+
}
|
|
271
|
+
if opts.period <= 0 {
|
|
272
|
+
return fmt.Errorf("--period is required")
|
|
273
|
+
}
|
|
274
|
+
query := strings.TrimSpace(strings.Join(args, " "))
|
|
275
|
+
return runMatchCommand(cmd, global, func(ctx context.Context, service matchCommandService) (cricinfo.NormalizedResult, error) {
|
|
276
|
+
return service.Partnerships(ctx, query, cricinfo.MatchInningsOptions{
|
|
277
|
+
LeagueID: opts.leagueID,
|
|
278
|
+
TeamQuery: opts.team,
|
|
279
|
+
Innings: opts.innings,
|
|
280
|
+
Period: opts.period,
|
|
281
|
+
})
|
|
282
|
+
})
|
|
283
|
+
},
|
|
284
|
+
}
|
|
285
|
+
partnershipsCmd.Flags().StringVar(&opts.team, "team", "", "Required: team ID/ref/alias")
|
|
286
|
+
partnershipsCmd.Flags().IntVar(&opts.innings, "innings", 0, "Required: innings number")
|
|
287
|
+
partnershipsCmd.Flags().IntVar(&opts.period, "period", 0, "Required: period number")
|
|
288
|
+
|
|
289
|
+
fowCmd := &cobra.Command{
|
|
290
|
+
Use: "fow <match>",
|
|
291
|
+
Short: "Show fall-of-wicket entries for a selected team innings period",
|
|
292
|
+
Long: strings.Join([]string{
|
|
293
|
+
"Resolve one match and team, select innings/period, and render detailed fall-of-wicket objects.",
|
|
294
|
+
"",
|
|
295
|
+
"Required flags:",
|
|
296
|
+
" --team <team>",
|
|
297
|
+
" --innings <n>",
|
|
298
|
+
" --period <n>",
|
|
299
|
+
}, "\n"),
|
|
300
|
+
Args: cobra.MinimumNArgs(1),
|
|
301
|
+
RunE: func(cmd *cobra.Command, args []string) error {
|
|
302
|
+
if strings.TrimSpace(opts.team) == "" {
|
|
303
|
+
return fmt.Errorf("--team is required")
|
|
304
|
+
}
|
|
305
|
+
if opts.innings <= 0 {
|
|
306
|
+
return fmt.Errorf("--innings is required")
|
|
307
|
+
}
|
|
308
|
+
if opts.period <= 0 {
|
|
309
|
+
return fmt.Errorf("--period is required")
|
|
310
|
+
}
|
|
311
|
+
query := strings.TrimSpace(strings.Join(args, " "))
|
|
312
|
+
return runMatchCommand(cmd, global, func(ctx context.Context, service matchCommandService) (cricinfo.NormalizedResult, error) {
|
|
313
|
+
return service.FallOfWicket(ctx, query, cricinfo.MatchInningsOptions{
|
|
314
|
+
LeagueID: opts.leagueID,
|
|
315
|
+
TeamQuery: opts.team,
|
|
316
|
+
Innings: opts.innings,
|
|
317
|
+
Period: opts.period,
|
|
318
|
+
})
|
|
319
|
+
})
|
|
320
|
+
},
|
|
321
|
+
}
|
|
322
|
+
fowCmd.Flags().StringVar(&opts.team, "team", "", "Required: team ID/ref/alias")
|
|
323
|
+
fowCmd.Flags().IntVar(&opts.innings, "innings", 0, "Required: innings number")
|
|
324
|
+
fowCmd.Flags().IntVar(&opts.period, "period", 0, "Required: period number")
|
|
325
|
+
|
|
326
|
+
deliveriesCmd := &cobra.Command{
|
|
327
|
+
Use: "deliveries <match>",
|
|
328
|
+
Short: "Show over-by-over and wicket timelines for a selected innings period",
|
|
329
|
+
Long: strings.Join([]string{
|
|
330
|
+
"Resolve one match and team, select innings/period, and render normalized over and wicket timelines from period statistics.",
|
|
331
|
+
"",
|
|
332
|
+
"Required flags:",
|
|
333
|
+
" --team <team>",
|
|
334
|
+
" --innings <n>",
|
|
335
|
+
" --period <n>",
|
|
336
|
+
}, "\n"),
|
|
337
|
+
Args: cobra.MinimumNArgs(1),
|
|
338
|
+
RunE: func(cmd *cobra.Command, args []string) error {
|
|
339
|
+
if strings.TrimSpace(opts.team) == "" {
|
|
340
|
+
return fmt.Errorf("--team is required")
|
|
341
|
+
}
|
|
342
|
+
if opts.innings <= 0 {
|
|
343
|
+
return fmt.Errorf("--innings is required")
|
|
344
|
+
}
|
|
345
|
+
if opts.period <= 0 {
|
|
346
|
+
return fmt.Errorf("--period is required")
|
|
347
|
+
}
|
|
348
|
+
query := strings.TrimSpace(strings.Join(args, " "))
|
|
349
|
+
return runMatchCommand(cmd, global, func(ctx context.Context, service matchCommandService) (cricinfo.NormalizedResult, error) {
|
|
350
|
+
return service.Deliveries(ctx, query, cricinfo.MatchInningsOptions{
|
|
351
|
+
LeagueID: opts.leagueID,
|
|
352
|
+
TeamQuery: opts.team,
|
|
353
|
+
Innings: opts.innings,
|
|
354
|
+
Period: opts.period,
|
|
355
|
+
})
|
|
356
|
+
})
|
|
357
|
+
},
|
|
358
|
+
}
|
|
359
|
+
deliveriesCmd.Flags().StringVar(&opts.team, "team", "", "Required: team ID/ref/alias")
|
|
360
|
+
deliveriesCmd.Flags().IntVar(&opts.innings, "innings", 0, "Required: innings number")
|
|
361
|
+
deliveriesCmd.Flags().IntVar(&opts.period, "period", 0, "Required: period number")
|
|
362
|
+
|
|
363
|
+
cmd.AddCommand(
|
|
364
|
+
liveCmd,
|
|
365
|
+
listCmd,
|
|
366
|
+
showCmd,
|
|
367
|
+
statusCmd,
|
|
368
|
+
scorecardCmd,
|
|
369
|
+
detailsCmd,
|
|
370
|
+
playsCmd,
|
|
371
|
+
situationCmd,
|
|
372
|
+
inningsCmd,
|
|
373
|
+
partnershipsCmd,
|
|
374
|
+
fowCmd,
|
|
375
|
+
deliveriesCmd,
|
|
376
|
+
)
|
|
377
|
+
return cmd
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
func runMatchCommand(
|
|
381
|
+
cmd *cobra.Command,
|
|
382
|
+
global *globalOptions,
|
|
383
|
+
fn func(ctx context.Context, service matchCommandService) (cricinfo.NormalizedResult, error),
|
|
384
|
+
) error {
|
|
385
|
+
service, err := newMatchService()
|
|
386
|
+
if err != nil {
|
|
387
|
+
return err
|
|
388
|
+
}
|
|
389
|
+
defer func() {
|
|
390
|
+
_ = service.Close()
|
|
391
|
+
}()
|
|
392
|
+
|
|
393
|
+
result, err := fn(cmd.Context(), service)
|
|
394
|
+
if err != nil {
|
|
395
|
+
return err
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
return cricinfo.Render(cmd.OutOrStdout(), result, cricinfo.RenderOptions{
|
|
399
|
+
Format: global.format,
|
|
400
|
+
Verbose: global.verbose,
|
|
401
|
+
AllFields: global.allFields,
|
|
402
|
+
})
|
|
403
|
+
}
|