The spending guard lets you cap how much the CLI can spend — essential when an AI agent drives the CLI. Any cart or checkout operation that would exceed the cap is refused with a non-zero exit code and a clearDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ivorpad/mercadona-cli/llms.txt
Use this file to discover all available pages before exploring further.
error: line on stderr, so agents stop instead of overspending. The guard is enforced at every write step, including the irreversible checkout submit.
Three ways to set the cap
You can configure the spending cap at three levels. The highest-precedence source wins:| Priority | Method | Example |
|---|---|---|
| 1 (highest) | --max <eur> flag on the command | --max 80 |
| 2 | MERCADONA_MAX_EUR environment variable | MERCADONA_MAX_EUR=100 |
| 3 (lowest) | [limits] max_eur in ~/.mercadona/config.toml | max_eur = 100 |
0 or leaving the option unset disables the guard entirely — no limit is enforced.
Config file (persistent, applies to every command)
Environment variable (session-scoped)
Flag (per-command, highest precedence)
Which commands enforce the cap
The spending guard applies to every command that writes the cart or advances the checkout:search, batch, product, categories, cart get, cart clear, checkout get) do not enforce the cap — they never spend or add to the cart total.
How cart set-many enforces the cap
set-many is the preventive enforcement path. When a --max is active, it:
- Fetches the current cart from the API.
- Folds every
<id> <qty>change onto the current lines (new items are priced concurrently, up toMERCADONA_CONCURRENCYparallel requests; items already in the cart reuse their cached price). - Estimates the resulting basket total.
- Refuses without writing if the estimate exceeds the cap — the cart is completely untouched.
- If the estimate is within the cap, issues the single
PutCartwrite. - Runs a post-write authoritative check against the real total returned by the API; if that real total still breaches the cap, it reverts the cart to its previous state.
set-many always leaves the cart unchanged. The same preventive pattern applies to cart add and cart set.
How checkout submit enforces the cap (fails closed)
checkout submit is the irreversible step and enforces the cap with the strictest policy — fails closed. With a cap configured:
- If the order total can be read and exceeds the cap → refuse with a non-zero exit.
- If the order total cannot be read for any reason → also refuse rather than proceed blind.
submit prints a warning that no budget guard is active and still proceeds. With a cap set, it never proceeds blind — an unreadable total is treated as a failure.
Error messages
When the guard fires, the error is printed to stderr and the command exits with code 1:checkout submit when the total can’t be verified:
Three distinct euro figures
These three amounts are easy to conflate but are completely separate concepts:| Figure | What it is | Where it applies |
|---|---|---|
| Minimum order ≈ 60€ | A floor — the product subtotal must clear this for checkout to proceed. The CLI prints a faltan X€… warning (to stderr) in cart get and checkout create when the basket is below it. | Set by Mercadona’s API; not controlled by the CLI. |
--max on cart commands | A ceiling on the product subtotal only. | cart add, cart set, cart set-many |
--max on checkout commands | A ceiling on the total including the delivery fee (~8.20€). Must be sized to cover products plus delivery. | checkout create, checkout set-delivery, checkout submit |