MCPcopy Create free account
hub / github.com/openclaw/gogcli / Run

Method Run

internal/cmd/analytics.go:115–192  ·  view source on GitHub ↗
(ctx context.Context, flags *RootFlags)

Source from the content-addressed store, hash-verified

113}
114
115func (c *AnalyticsReportCmd) Run(ctx context.Context, flags *RootFlags) error {
116 u := ui.FromContext(ctx)
117 account, err := requireAccount(flags)
118 if err != nil {
119 return err
120 }
121
122 plan, err := newAnalyticsReportPlan(analyticsReportInput{
123 Property: c.Property,
124 From: c.From,
125 To: c.To,
126 Dimensions: c.Dimensions,
127 Metrics: c.Metrics,
128 Max: c.Max,
129 Offset: c.Offset,
130 })
131 if err != nil {
132 return err
133 }
134
135 svc, err := analyticsDataService(ctx, account)
136 if err != nil {
137 return err
138 }
139
140 resp, err := svc.Properties.RunReport(plan.Property, plan.Request).Context(ctx).Do()
141 if err != nil {
142 return err
143 }
144
145 if outfmt.IsJSON(ctx) {
146 if err := outfmt.WriteJSON(ctx, stdoutWriter(ctx), map[string]any{
147 "property": plan.Property,
148 "from": plan.From,
149 "to": plan.To,
150 "dimensions": plan.Dimensions,
151 "metrics": plan.Metrics,
152 "row_count": resp.RowCount,
153 "dimensionHeaders": resp.DimensionHeaders,
154 "metricHeaders": resp.MetricHeaders,
155 "rows": resp.Rows,
156 }); err != nil {
157 return err
158 }
159 if len(resp.Rows) == 0 {
160 return failEmptyExit(c.FailEmpty)
161 }
162 return nil
163 }
164
165 if len(resp.Rows) == 0 {
166 u.Err().Println("No analytics rows")
167 return failEmptyExit(c.FailEmpty)
168 }
169
170 headers := make([]string, 0, len(plan.Dimensions)+len(plan.Metrics))
171 for _, d := range plan.Dimensions {
172 headers = append(headers, strings.ToUpper(d))

Callers

nothing calls this directly

Calls 15

FromContextFunction · 0.92
IsJSONFunction · 0.92
WriteJSONFunction · 0.92
requireAccountFunction · 0.85
newAnalyticsReportPlanFunction · 0.85
analyticsDataServiceFunction · 0.85
stdoutWriterFunction · 0.85
failEmptyExitFunction · 0.85
tableWriterFunction · 0.85
sanitizeTabFunction · 0.85
analyticsDimensionValueFunction · 0.85
analyticsMetricValueFunction · 0.85

Tested by

no test coverage detected