(ctx context.Context, flags *RootFlags)
| 217 | } |
| 218 | |
| 219 | func (c *SearchConsoleSitemapsListCmd) Run(ctx context.Context, flags *RootFlags) error { |
| 220 | u := ui.FromContext(ctx) |
| 221 | siteURL := strings.TrimSpace(c.SiteURL) |
| 222 | if siteURL == "" { |
| 223 | return usage("empty siteUrl") |
| 224 | } |
| 225 | |
| 226 | account, err := requireAccount(flags) |
| 227 | if err != nil { |
| 228 | return err |
| 229 | } |
| 230 | |
| 231 | svc, err := searchConsoleService(ctx, account) |
| 232 | if err != nil { |
| 233 | return err |
| 234 | } |
| 235 | call := svc.Sitemaps.List(siteURL).Context(ctx) |
| 236 | if v := strings.TrimSpace(c.SitemapIndex); v != "" { |
| 237 | call = call.SitemapIndex(v) |
| 238 | } |
| 239 | resp, err := call.Do() |
| 240 | if err != nil { |
| 241 | return wrapSearchConsoleError(err) |
| 242 | } |
| 243 | |
| 244 | rows := resp.Sitemap |
| 245 | if outfmt.IsJSON(ctx) { |
| 246 | if err := outfmt.WriteJSON(ctx, stdoutWriter(ctx), map[string]any{ |
| 247 | "sitemaps": rows, |
| 248 | }); err != nil { |
| 249 | return err |
| 250 | } |
| 251 | if len(rows) == 0 { |
| 252 | return failEmptyExit(c.FailEmpty) |
| 253 | } |
| 254 | return nil |
| 255 | } |
| 256 | |
| 257 | if len(rows) == 0 { |
| 258 | u.Err().Println("No Search Console sitemaps") |
| 259 | return failEmptyExit(c.FailEmpty) |
| 260 | } |
| 261 | |
| 262 | w, flush := tableWriter(ctx) |
| 263 | defer flush() |
| 264 | fmt.Fprintln(w, "PATH\tTYPE\tPENDING\tWARNINGS\tERRORS\tLAST_SUBMITTED\tLAST_DOWNLOADED\tCONTENTS") |
| 265 | for _, item := range rows { |
| 266 | if item == nil { |
| 267 | continue |
| 268 | } |
| 269 | fmt.Fprintf(w, "%s\t%s\t%t\t%d\t%d\t%s\t%s\t%s\n", |
| 270 | sanitizeTab(item.Path), |
| 271 | sanitizeTab(item.Type), |
| 272 | item.IsPending, |
| 273 | item.Warnings, |
| 274 | item.Errors, |
| 275 | sanitizeTab(item.LastSubmitted), |
| 276 | sanitizeTab(item.LastDownloaded), |
nothing calls this directly
no test coverage detected