The DeployHQ CLI provides several ways to create and manage deployments, from a quick one-liner to detailed deployment management commands.

## One-Command Deploy (dhq launch)

`dhq launch` takes a project folder to a live URL on DeployHQ's managed infrastructure in a single step. It detects your framework, provisions the right target -- **Static Hosting** or a **Managed VPS** -- connects your repository, deploys, and prints the URL when it finishes.

```bash
# Interactive: detect the framework and prompt for anything missing
dhq launch

# Force Static Hosting with a chosen subdomain
dhq launch --static --subdomain my-app

# Provision a Managed VPS in a specific region and size
dhq launch --vps --accept-cost --region lon1 --size s-1vcpu-1gb
```

A Managed VPS is a managed resource -- free for early customers during the beta, and billed monthly afterwards. Because it has a cost, provisioning one non-interactively requires `--accept-cost`; `--yes` on its own never provisions a VPS.

For CI or AI agents, `dhq launch` is fully non-interactive with structured output:

```bash
# Structured JSON, never prompts
dhq launch --static --json

# Preview the intended actions and cost without making any changes
dhq launch --vps --dry-run --json
```

Useful flags:

| Flag | Description |
|------|-------------|
| `--static` / `--vps` | Force the deployment target |
| `--subdomain` | Static Hosting subdomain |
| `--region` / `--size` | Managed VPS region and size slugs |
| `--branch` | Branch to deploy (defaults to the repository default) |
| `--project` | Reuse an existing project instead of creating one |
| `--accept-cost` | Acknowledge Managed VPS cost (required for non-interactive VPS provisioning) |
| `--cleanup-on-failure` | Remove the provisioned server if the deploy fails |
| `--dry-run` | Print intended actions and cost without executing |
| `--non-interactive` / `--yes` | Never prompt; fail fast on ambiguity (for CI and agents) |

After the first run, `dhq launch` writes a `.deployhq.toml` file, so subsequent deployments are just `dhq deploy`.

## Quick Deploy

The `dhq deploy` shortcut is the fastest way to deploy:

```bash
# Deploy the default project to the default server
dhq deploy --wait

# Deploy a specific project to a specific server
dhq deploy -p my-app -s production --wait

# Deploy a specific branch
dhq deploy -p my-app -s staging --branch develop --wait

# Deploy a specific commit
dhq deploy -p my-app -s production --revision abc123 --wait
```

### The --wait Flag

By default, `dhq deploy` queues the deployment and returns immediately. Add `--wait` to watch the deployment until it completes or fails.

### Live TUI Progress

When running in an interactive terminal with `--wait`, the CLI displays a real-time TUI (text user interface) showing deployment steps as they happen:

```
Deploying my-app to Production Web...

  Checking access to repository              [done]
  Updating repository                        [done]
  Running build commands                     [in progress]
    npm install                              [done]
    npm run build                            [running]
  Transferring files to server               [pending]

Elapsed: 1m 23s
```

### Fuzzy Server Matching

Server names are fuzzy-matched, so you do not need to type the exact name:

```bash
# "prod" matches "Production Web"
dhq deploy -p my-app -s prod --wait

# "fedora" matches "DO - FEDORA"
dhq deploy -p my-app -s fedora --wait
```

If multiple servers match, the CLI presents a picker in interactive mode, or returns an error in non-interactive mode.

### Auto-Server Selection

If your project has only one server, the CLI selects it automatically -- no `-s` flag needed.

## Deployment Management

For more control, use the `dhq deployments` subcommands.

### Listing Deployments

```bash
# List recent deployments
dhq deployments list -p my-app

# JSON output with specific fields
dhq deployments list -p my-app --json identifier,status,branch
```

### Viewing Deployment Details

```bash
dhq deployments show <deployment-id> -p my-app
```

### Creating a Deployment (Full Control)

```bash
dhq deployments create -p my-app \
  --server production \
  --branch main \
  --revision abc123
```

### Watching a Deployment

Monitor an in-progress deployment:

```bash
dhq deployments watch <deployment-id> -p my-app
```

### Viewing Deployment Logs

```bash
dhq deployments logs <deployment-id> -p my-app
```

On failure, the CLI automatically shows logs and suggests recovery commands.

## Aborting a Deployment

Stop a running deployment:

```bash
dhq deployments abort <deployment-id> -p my-app
```

## Rolling Back

Rollback to the previous deployment:

```bash
# Shortcut
dhq rollback <deployment-id> -p my-app

# Or via subcommand
dhq deployments rollback <deployment-id> -p my-app
```

## Retrying a Failed Deployment

Retry the last failed deployment:

```bash
# Shortcut
dhq retry <deployment-id> -p my-app

# Or via subcommand
dhq deployments retry <deployment-id> -p my-app
```

## Deploying to Server Groups

If your project has server groups configured, you can deploy to all servers in a group simultaneously by specifying the group name with the `-s` flag:

```bash
dhq deploy -p my-app -s "Production Group" --wait
```

## Using the Latest Deployed Commit

Deploy from the last deployed revision to the latest commit:

```bash
dhq deploy -p my-app -s production --use-latest --wait
```

## Failure Handling

When a deployment fails with `--wait`, the CLI automatically:

1. Shows the deployment logs
2. Displays suggested next commands (retry, rollback)
3. Returns a non-zero exit code for CI/CD integration

Example failure output:

```
Deployment failed.

Suggested actions:
  dhq retry abc123 -p my-app        # Retry this deployment
  dhq rollback abc123 -p my-app     # Rollback to previous version
  dhq deployments logs abc123 -p my-app  # View full logs
```

## Testing Connectivity

Before deploying, you can verify that DeployHQ can reach your repository and servers:

```bash
# Test all servers in a project
dhq test-access -p my-app

# Test a specific server
dhq test-access -p my-app -s production

# Wait for the test to complete
dhq test-access -p my-app --wait
```

This runs the same connectivity checks that DeployHQ performs before a deployment, helping you catch configuration issues (wrong credentials, firewall rules, SSH key problems) before they cause a deployment failure.

## Common Workflows

### Deploy After a Git Push

```bash
git push origin main
dhq deploy -p my-app -s production --wait
```

### Check Status Before Deploying

```bash
# View current server revisions
dhq servers list -p my-app

# View recent deployment history
dhq deployments list -p my-app

# Then deploy
dhq deploy -p my-app -s production --wait
```

### Deploy and Open in Browser

```bash
dhq deploy -p my-app --wait && dhq open my-app
```
