# Hosting, the CLI day to day

> Link a directory to a site, follow logs, pull variables, open, promote, and what `hosting up` uploads and skips.

Source: https://docs.infaris.com/en/pulseguard/hosting-cli

The commands you use every day. The full list is under `infaris-guard hosting commands`; the
[quickstart](hosting-quickstart) shows how to begin.

## Help and overview

```bash
infaris-guard hosting --help          # the everyday commands by task
infaris-guard hosting env pull --help # usage and flags of one command
infaris-guard hosting commands        # every command
```

A command that does not exist gives exit code 2 and names the closest one (`linkk` gives `hosting link`). That also
holds for `--help`, so a CI script or agent never sees success.

| Exit code | Meaning |
| --- | --- |
| 1 | Other error |
| 2 | Wrong usage (unknown command, missing flag) |
| 3 | Not signed in |
| 4 | Not found |
| 5 | Conflict (already exists) |
| 6 | Forbidden |
| 7 | Network error or timeout |

`--json` gives one JSON result and `--yes` answers a question with yes.

## Link a directory: `link` and `unlink`

```bash
infaris-guard hosting link my-shop   # name, domain or id
infaris-guard hosting unlink
```

`link` writes `.infaris/hosting.json` for a site that already exists, without publishing anything. Without an argument
you pick from a list in a terminal. Without a terminal (or with `--json`/`--yes`) it stops with exit code 2 and lists
your sites. The link remembers where the site runs. In a terminal `link` asks whether `.infaris/` may go into
`.gitignore`. `unlink` removes the link; the site stays.

In a linked directory no command needs `--site`.

## `--site` with a name or domain

`--site` takes an id, a name or a domain:

```bash
infaris-guard hosting deploys --site my-shop
infaris-guard hosting deploys --site shop.example.com
```

A URL works too; `https://` and a trailing slash are ignored. Case does not matter. An unknown name gives exit code 4
and a list of your sites. If two sites share a name, use the id or the domain. With a deploy token only the id works.

## Follow logs

```bash
infaris-guard hosting logs -n 100        # the last 100 lines, oldest first
infaris-guard hosting logs -f            # keeps showing new lines until Ctrl+C
infaris-guard hosting logs -f --json     # one JSON object per line (NDJSON)
```

`--follow` (`-f`) shows the last lines, then asks for new ones every two seconds. Each line appears once, in time
order. A network hiccup does not stop following; being signed out or a deleted site does. `--lines` (`-n`) sets the
number of lines; `--limit` wins when you give both. Text is oldest first, like `tail`. `--json` without `-f` keeps the
API order (newest first). `--follow` together with `--to` or `--cursor` is not allowed.

## Variables: `env pull` and `env add`

```bash
infaris-guard hosting env pull                 # writes to .env.local
infaris-guard hosting env pull .env --dry-run  # only shows what would be added
printf '%s' "$VALUE" | infaris-guard hosting env add API_KEY --value-stdin
infaris-guard hosting env rm API_KEY
```

`env pull` writes the **values** of the site's non-secret variables for development (or `--environment preview|production`;
production only for an owner or admin) into a local env file, as `vercel env pull` does. A secret is never pulled: a
new secret gets an empty line with a comment, a secret already in the file keeps its local value. A name already in
the file gets the value from Hosting; other lines stay and nothing is removed. The file gets mode 600 and the output
names keys only, never a value. If the file is not in `.gitignore`, `env pull` warns. With an API key this needs the
`env:pull` permission and never gets production.

`env add` is the same as `env set`: the value comes only from stdin or a file, never from an argument. `env rm` and
`env remove` are the same as `env unset`.

## `open` and `promote`

```bash
infaris-guard hosting open               # the site's address in the browser
infaris-guard hosting open --dashboard   # the site's page in Guard
infaris-guard hosting promote <previewId>
```

`open` works for the linked site, with `--site`, or with the name of an app in a stack (`hosting open web`). Without a
terminal, with `--json` or with `--no-browser` it only prints the URL. `promote` makes a preview the live release; it
is the same as `hosting preview promote`. Find preview ids with `hosting preview list`.

## What `hosting up` asks and uploads

`hosting up` stops before it creates anything when the directory:

- is the root of a Git repository with workspaces (`package.json` with workspaces, `pnpm-workspace.yaml`,
  `turbo.json`, `lerna.json`, `nx.json`, `rush.json` or `go.work`), or
- holds more than 2,000 files or 200 MB (not counting `.git`, `node_modules` and dot files).

In a terminal it asks (default no). Without a terminal it stops with exit code 2; only `--yes` goes on, with a warning.
Rather run `up` in the app's own directory (`--dir apps/web`). This also applies to `hosting init --template`.

Before the upload (`up`, `deploy` and `preview deploy`) you see how many files and MB it uploads and what it skips, for
example `node_modules/`, `.git/` and `.env`. A static site publishes only its output directory; config and repository
files such as `infaris.toml`, `README*` and lockfiles never go online. The full list and `.infarisignore` are under
[starters](hosting-starters).

`.infaris/` never goes into your `.gitignore` unasked. In a terminal `up` asks; without a terminal it only names the
line and the file.

## Shell completion

```bash
infaris-guard completion bash > /etc/bash_completion.d/infaris-guard
infaris-guard completion zsh  > ~/.zsh/completions/_infaris-guard   # or: source <(infaris-guard completion zsh)
infaris-guard completion fish > ~/.config/fish/completions/infaris-guard.fish
```

Every level below `hosting` completes, including `db` and the aliases (`env add`, `env rm`, `promote`). After `-` the
command's own flags come first, then the shared flags such as `--site`, `--json` and `--yes`. The script asks the CLI
itself for candidates, so new commands work without a new script.
