> ## Documentation Index
> Fetch the complete documentation index at: https://docs.occtoo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# occtoo lifecycles

> Manage lifecycles: steps and rules that tell how far an entry of a card has come

A lifecycle is a list of steps, each with rules, that tells how far an entry of a card has come: which step it is stuck at and which rules it fails.

A lifecycle definition is one JSON document, too large for prompts. `create`, `edit` and `preview` read it from `--file` or stdin.

## List and show

```bash theme={null}
occtoo lifecycles list products --state ready
occtoo lifecycles show <ID>
```

`list` takes the card definition id, because the API has no call that lists every card. `show` prints the state of the lifecycle and the steps of its pending definition.

| Flag (`list`) | Description |
| - | - |
| `--state <STATE>` | `draft`, `initializing` or `ready` |
| `--limit <LIMIT>` | Maximum number to return. Default `100` |

## The definition

`briefing`, `applicability` and `precondition` are optional. `assertion`, `precondition` and `applicability` are [search predicates](https://docs.occtoo.com/cli/commands/cards.md#search-predicates).

```json theme={null}
{
  "name": "Ready to publish",
  "steps": [
    {
      "slug": "basics",
      "name": "Basics",
      "rules": [
        {
          "slug": "has-title",
          "severity": "Error",
          "message": "A title is required",
          "assertion": { "hasValue": { "property": "title" } }
        }
      ]
    }
  ]
}
```

Severities are `Error`, `Warning` and `Advisory`. The API checks the definition and names the field that is wrong.

## Try, create and activate

```bash theme={null}
occtoo lifecycles preview products --file definition.json --sample-size 50
occtoo lifecycles create products --file definition.json
occtoo lifecycles activate <ID>
```

* `preview` tries a definition on a sample of entries and saves nothing. `--sample-size` defaults to `25`.
* `create` saves the definition as a new lifecycle draft.
* `activate` activates the pending definition and waits until the existing entries are assessed. Progress goes to stderr. Ctrl-C stops the waiting, not the assessment. `show` tells you whether the lifecycle is still `Initializing` or `Ready`.

## Change an active lifecycle

Changes go through a pending definition, which does nothing until you activate it:

```bash theme={null}
occtoo lifecycles show <ID> --output json | jq .pendingDefinition > definition.json
occtoo lifecycles edit <ID> --file definition.json
occtoo lifecycles activate <ID>
```

`edit` replaces the whole pending definition, including anything someone else saved after you ran `show`. To throw the pending definition away and keep the active revision, run `discard`:

```bash theme={null}
occtoo lifecycles discard <ID> --yes
```

`edit`, `activate`, `discard` and `delete` read the lifecycle right before they act and send its version along, so they fail instead of overwriting a lifecycle that changed in between.

## Assessments and revisions

```bash theme={null}
occtoo lifecycles assessment <ID> sku-1
occtoo lifecycles revision <ID> 3
```

* `assessment` shows what a lifecycle says about one entry, rule by rule. It reads the saved result and assesses nothing. To find entries by how far they have come, use `occtoo cards entries search --lifecycle <ID> --state incomplete`.
* `revision` shows a definition that was activated. The number is the `Active revision` that `show` prints.

## Delete a lifecycle

```bash theme={null}
occtoo lifecycles delete <ID> --yes
```

Deletes a lifecycle and what it assessed.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.