# CLI

> Install the monitorly CLI, sign in from a browser or with a token, and keep a project's checks, status pages and maintenance in a file in your repository.

`monitorly` keeps a project's checks, status pages and maintenance windows in a [`monitorly.yaml`](https://docs.monitorly.cloud/cli/monitorly-yaml.md) in your repository, drafts that file from what the repository already declares, checks a deploy from several countries, and installs private nodes. It is built for coding agents and CI as much as for people: every command has `--json` and stable exit codes.

## Install

```sh title="Linux, x86_64 or aarch64"
curl -fsSL https://gw.monitorly.cloud/install-cli.sh | sh
```

The script needs no root. It downloads the binary, checks its SHA-256 and puts it in `~/.local/bin/monitorly`; set `MONITORLY_BIN_DIR` for another directory. If that directory is not on your `PATH`, the script says how to add it and changes nothing itself. Running it again installs the current version.

There are no macOS or Windows builds yet.

## Sign in

```sh title="In a terminal"
monitorly login --api-url https://app.monitorly.cloud
```

On a terminal this opens the browser: you sign in, choose the workspace, the project and the access (read or write), and the CLI stores the sign-in in `~/.config/monitorly/credentials` (mode 0600). It refreshes itself; a sign-in unused for 30 days ends. Without an account, `monitorly signup --api-url https://app.monitorly.cloud` opens the sign-up page and continues the same way.

For CI and agents without a browser, create a personal API token in the dashboard (**Settings → API tokens**) and pass it in the environment:

```sh title="CI"
export MONITORLY_TOKEN=mly_…
export MONITORLY_API_URL=https://app.monitorly.cloud
monitorly verify-deploy
```

`MONITORLY_TOKEN` wins over the stored sign-in. There is deliberately no `--token` flag: a flag would show in the process list. The CLI never prints a token.

## A typical flow

```sh title="In your repository"
monitorly discover --out monitorly.yaml   # draft checks from compose files, Kubernetes, Terraform, nginx, Caddy, cron…
monitorly node list                       # pick nodes for each check
monitorly plan                            # what would change; nothing is applied
monitorly apply                           # apply exactly that plan, after confirmation
```

After that, edit `monitorly.yaml` with the rest of your code, and run `monitorly plan` in CI to see drift.

- [Commands](https://docs.monitorly.cloud/cli/commands.md): every command, its flags and output.
- [`monitorly.yaml`](https://docs.monitorly.cloud/cli/monitorly-yaml.md): the file format.
- [`monitorly discover`](https://docs.monitorly.cloud/cli/discover.md): what it reads, what it never opens, and how findings become checks.

## Output and exit codes

Results go to stdout, explanations and prompts to stderr. With `--json`, stdout is one JSON document, also for errors: `{"error": {"code": "…", "message": "…"}}`.

| Exit code | Meaning                                                                                                        |
| --------- | -------------------------------------------------------------------------------------------------------------- |
| 0         | Success. `plan`: no changes. `--dry-run`: the plan is shown                                                    |
| 1         | Error, or for `test` and `verify-deploy`: at least one check did not pass                                      |
| 2         | Usage error: an unknown flag, an invalid argument, token or URL                                                |
| 3         | Nothing done: `plan` found changes, or an action waits for confirmation (no `--yes`, no terminal, or `--json`) |

The API's own error codes come through as they are (`token.scope_missing`, `config.plan_stale`, `check.invalid_url`), with the HTTP status and the field pointers in `detail`.
