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

Method Run

internal/cmd/searchconsole.go:137–204  ·  view source on GitHub ↗
(ctx context.Context, flags *RootFlags)

Source from the content-addressed store, hash-verified

135}
136
137func (c *SearchConsoleQueryCmd) Run(ctx context.Context, flags *RootFlags) error {
138 u := ui.FromContext(ctx)
139 account, err := requireAccount(flags)
140 if err != nil {
141 return err
142 }
143
144 plan, err := c.plan(stdinReader(ctx))
145 if err != nil {
146 return err
147 }
148
149 svc, err := searchConsoleService(ctx, account)
150 if err != nil {
151 return err
152 }
153 resp, err := svc.Searchanalytics.Query(plan.SiteURL, plan.Request).Context(ctx).Do()
154 if err != nil {
155 return wrapSearchConsoleError(err)
156 }
157
158 if outfmt.IsJSON(ctx) {
159 if err := outfmt.WriteJSON(ctx, stdoutWriter(ctx), map[string]any{
160 "site_url": plan.SiteURL,
161 "from": plan.Request.StartDate,
162 "to": plan.Request.EndDate,
163 "type": plan.queryType(),
164 "dimensions": plan.Request.Dimensions,
165 "response_aggregation_type": resp.ResponseAggregationType,
166 "rows": resp.Rows,
167 }); err != nil {
168 return err
169 }
170 if len(resp.Rows) == 0 {
171 return failEmptyExit(c.FailEmpty)
172 }
173 return nil
174 }
175
176 if len(resp.Rows) == 0 {
177 u.Err().Println("No Search Console rows")
178 return failEmptyExit(c.FailEmpty)
179 }
180
181 headers := requestSearchConsoleDimensions(plan.Request, resp.Rows)
182 headers = append(headers, "CLICKS", "IMPRESSIONS", "CTR", "POSITION")
183
184 w, flush := tableWriter(ctx)
185 defer flush()
186 fmt.Fprintln(w, strings.Join(headers, "\t"))
187 for _, row := range resp.Rows {
188 if row == nil {
189 continue
190 }
191 values := make([]string, 0, len(headers))
192 for i := range headers[:len(headers)-4] {
193 values = append(values, sanitizeTab(searchConsoleKey(row, i)))
194 }

Callers

nothing calls this directly

Calls 15

planMethod · 0.95
FromContextFunction · 0.92
IsJSONFunction · 0.92
WriteJSONFunction · 0.92
requireAccountFunction · 0.85
stdinReaderFunction · 0.85
searchConsoleServiceFunction · 0.85
wrapSearchConsoleErrorFunction · 0.85
stdoutWriterFunction · 0.85
failEmptyExitFunction · 0.85
tableWriterFunction · 0.85

Tested by

no test coverage detected