# CLI

Everything Rank does can run under `wp sleek rank`, so page groups can be
provisioned and their data refreshed from deploy scripts, cron jobs and
coding agents. This page shows the common workflows;
[WP-CLI commands](/docs/rank/reference/cli.md) lists every command with its
options and examples, generated from the commands themselves.

## Provisioning a page group

`wp sleek rank page-group create` needs `--name`, `--base-page` and
`--url-pattern`, and creates the group as a draft unless `--status=publish` is
given. `--data-sources` and `--mappings` take JSON arrays in the shapes
[Data sources](/docs/rank/page-groups/data-sources.md#configuring-sources-from-wp-cli-or-rest)
and [Mappings](/docs/rank/page-groups/mappings.md) describe, and `--porcelain`
prints only the new id:

```bash
id=$(wp sleek rank page-group create --name="City pages" --base-page=42 \
  --url-pattern="cities/{slug}" --status=publish \
  --data-sources='[{"type":"json_file","config":{"path":"data/cities.json"},"cacheDuration":86400}]' \
  --mappings='[{"type":"tag","target":"title","field":"seoTitle"},{"type":"meta","target":"description","field":"metaDescription"}]' \
  --porcelain)
wp sleek rank reload "$id"
```

A new group serves no pages until its data is loaded, so run
`wp sleek rank reload <id>` after `create`, and again after changing its
sources. `wp sleek rank page-group list`, `get`, `update` and `delete` manage
existing groups; `list` and `get` with `--format=json` print the full
configuration.

## Refreshing data

- `wp sleek rank reload <id>` fetches one group's sources again and prints how
  many rows it stored, with a warning that counts the rows skipped because an
  earlier row has the same slug; `--all` does the same for every published
  group. The first source that fails stops the command with its error.
- `wp sleek rank cache sync` refreshes every published group, or one with
  `--group`, keeps going past a failure, reports the failures, and exits with
  an error when there were any. This is the command for a deploy or a
  scheduled job.
- `wp sleek rank cache status` reports the active caches and how many expired
  rows are waiting for cleanup.
- `wp sleek rank cache cleanup` removes a bounded batch of expired rows that no
  published group uses. The twice-daily cleanup does the same and also
  removes rows that no page group refers to.

A failed refresh keeps the previous rows, so live pages never lose their last
working data.

## Inspecting what a group generates

- `wp sleek rank items <id>` lists a group's cached rows, or one with
  `--slug`, as a table, JSON or CSV.
- `wp sleek rank routes` prints every generated public URL as JSON, or their
  number with `--format=count`.
- `wp sleek rank sitemap` prints the sitemap entries Rank generates, for all
  groups or one with `--group`, as a table, JSON or sitemap XML.

## Rewrite rules

Creating, changing or deleting a page group rebuilds the rewrite rules on the
next request, so `wp sleek rank flush-rewrites` is optional. Run it to apply a
new URL pattern at once, for example in a deploy before warming caches.

## Credentials

`wp sleek rank settings set` stores the Google Sheets API key
(`--google-sheets-key`) or the Notion integration token (`--notion-token`)
without opening the [Settings](/docs/rank/settings.md) page; `--validate` checks
them with the provider first and stops when they are rejected.

## From the workspace assistant

The workspace assistant can run Rank's commands for you, except
`wp sleek rank settings set`, which never reaches it. Deleting a page group and
`wp sleek rank cache cleanup` ask for your confirmation before they run.
