OpenLens CLI written in Go on top of the REST API (https://docs.openlens.com/api-reference/)
  • Go 91.2%
  • Shell 8.8%
Find a file Use this template
2026-06-08 12:59:13 -07:00
cmd/openlens Build initial OpenLens CLI 2026-06-08 06:38:57 -07:00
internal Build initial OpenLens CLI 2026-06-08 06:38:57 -07:00
.env.example Build initial OpenLens CLI 2026-06-08 06:38:57 -07:00
.gitignore Initial commit 2026-06-08 12:44:29 +00:00
go.mod Build initial OpenLens CLI 2026-06-08 06:38:57 -07:00
install.sh Add install script 2026-06-08 12:59:13 -07:00
LICENSE Initial commit 2026-06-08 12:44:29 +00:00
README.md Add install script 2026-06-08 12:59:13 -07:00

go-openlens-cli

OpenLens CLI written in Go on top of the beta REST API.

Docs used:

Build

go build -o openlens ./cmd/openlens

Install

From the repo host:

curl -fsSL 'http://bread49:3030/api/v1/repos/aman/go-openlens-cli/raw/install.sh?ref=main' | bash

The installer downloads the source archive, builds ./cmd/openlens, and installs the binary to ~/.local/bin/openlens.

Override the install directory or source ref when needed:

curl -fsSL 'http://bread49:3030/api/v1/repos/aman/go-openlens-cli/raw/install.sh?ref=main' \
  | OPENLENS_CLI_INSTALL_DIR=/usr/local/bin OPENLENS_CLI_REF=main bash

Requirements: curl, tar, and Go.

For a private repo, pass the same auth to the script so it can download the source archive:

curl -fsSL -u "$GITEA_USER:$GITEA_TOKEN" \
  'http://bread49:3030/api/v1/repos/aman/go-openlens-cli/raw/install.sh?ref=main' \
  | OPENLENS_CLI_CURL_USER="$GITEA_USER:$GITEA_TOKEN" bash

In this sandbox, use a writable Go cache:

GOCACHE=/tmp/go-openlens-cli-gocache go test ./...
GOCACHE=/tmp/go-openlens-cli-gocache go build -o /tmp/openlens ./cmd/openlens

Configuration

Production defaults to:

OPENLENS_BASE_URL=https://openlens.com/api
OPENLENS_API_KEY=...

Development uses the ignored .env file:

DEV_OPENLENS_URL=https://openlens-dev.up.railway.app
DEV_OPENLENS_API_KEY=...

The CLI normalizes host-only URLs by appending /api, so both of these are valid:

openlens --base-url https://openlens.com/api limits
openlens --base-url https://openlens-dev.up.railway.app limits

Profile behavior:

  • --profile auto prefers OPENLENS_*, then DEV_OPENLENS_*, then production base URL.
  • --profile dev requires DEV_OPENLENS_URL and uses DEV_OPENLENS_API_KEY.
  • --profile prod uses OPENLENS_BASE_URL or https://openlens.com/api, and OPENLENS_API_KEY.

OPENLENS_PROJECT_ID or global --project-id can provide a default project for project-scoped commands.

Commands

openlens --profile dev config
openlens --profile dev platforms
openlens --profile dev projects list
openlens --profile dev runs --project-id <project-id>
openlens --profile dev run start --project-id <project-id>
openlens --profile dev run status --project-id <project-id> --run-id <run-id>
openlens --profile dev visibility --project-id <project-id> --type overview
openlens --profile dev trends --project-id <project-id> --days 30 --compare
openlens --profile dev sources --project-id <project-id> --limit 20
openlens --profile dev report visibility --project-id <project-id> --run-id <run-id> --out report.pdf
openlens --profile dev onboard analyze --url https://example.com

Use raw for beta endpoints that do not have first-class commands yet:

openlens --profile dev raw --query projectId=<project-id> GET /visibility

Current Dev Smoke Test

The dev deployment is reachable at https://openlens-dev.up.railway.app/api, but the current .env API key returns:

openlens API returned HTTP 401: {"error":"Not authenticated"}

That matches the API docs' 401 behavior for missing, malformed, or revoked keys. Once a valid dev key is available, the same commands should exercise the real API without code changes.