CLI commands and runtime support
Arcane's Go CLI gives operators and automation one command surface for managing workloads, platform resources, and access. It turns local command input into authenticated API calls for a selected environment, then returns readable terminal output or stable JSON for scripts. See the parent page, Command-line interface, for the wider CLI architecture.
Command surface
The command tree groups actions by the Arcane product area that they control. Most groups support read, create, update, and delete actions where the server permits them, while action groups also start workloads, check health, or trigger maintenance.
Workload command groups
The workload commands manage the resources that make up an Arcane deployment. They let an operator inspect resources, change their state, create or remove them, and follow update or sync status.
| Command group | Product purpose |
|---|---|
containers | Inspect and operate running containers. |
images | List, pull, remove, prune, upload, and check Docker images. |
projects | Manage Compose-based applications and their services. |
volumes | Manage persistent storage and its use. |
networks | Manage container networks and their use. |
environments | Select and maintain the Arcane environments that receive commands. |
registries | Manage container registry connections. |
templates | Manage Compose templates and shared variables. |
repos | Manage Git repositories used by project automation. |
gitops | Manage repository-backed sync definitions and trigger syncs. |
These groups share a resource-oriented shape. List commands expose filtering and paging, detail commands accept a resource reference, and mutating commands return a success result only after the API accepts the action. The projects, images, containers, and gitops groups also expose update or sync views so operators can act on change rather than only view current state.
References: cli/…/root.go• L249-269 cli/…/cmd.go• L60-83 cli/…/cmd.go• L1-16 cli/…/cmd.go• L55-79 cli/…/cmd.go• L45-50 cli/…/cmd.go• L36-41 cli/…/cmd.go• L47-52 cli/…/cmd.go• L43-47 cli/…/cmd.go• L63-68 cli/…/cmd.go• L36-41 cli/…/cmd.go• L45-50
Administration command groups
The admin tree manages the people, permissions, credentials, and records that govern Arcane use. It keeps manual access grants separate from OIDC-driven grants so each source remains clear to an operator.
| Command group | Product purpose |
|---|---|
admin users | Create, inspect, update, and remove users. |
admin roles | Manage permission sets and assign them globally or per environment. |
admin oidc-mappings | Map OIDC claim values to role assignments at login. |
admin api-keys | Create and manage scoped API credentials. |
admin events | Review or remove platform event records. |
admin notifications | Inspect, test, and remove notification provider settings. |
The access commands reflect the server's scope rules. A role or API-key grant can be global or tied to one environment, and the CLI sends that scope as part of the requested change. The server remains the authority for permission checks; the CLI reports a denied action as an error instead of presenting a false success.
References: cli/…/cmd.go• L13-27 cli/…/cmd.go• L41-49 cli/…/cmd.go• L1-6 cli/…/cmd.go• L321-401 cli/…/cmd.go• L35-44 cli/…/cmd.go• L80-85 cli/…/cmd.go• L25-30 cli/…/cmd.go• L23-33 cli/…/action_error_handling_test.go• L11-79
Platform and utility command groups
The remaining command groups support the CLI itself and the Arcane platform around workloads. They cover login, local setup, diagnostics, system actions, schedules, settings, version checks, completion, generated credentials, and CLI updates.
| Command group | Product purpose |
|---|---|
auth | Log in, log out, inspect identity, change passwords, refresh tokens, and exchange CI tokens. |
config | Set, inspect, test, initialize, and back up local CLI settings. |
system | Run system-wide cleanup, container actions, Docker inspection, conversion, and upgrades. |
settings | Read and update environment settings, including public settings. |
jobs | Read and change platform job schedules. |
updater | Inspect or run image update work and view update history. |
version | Show CLI or server version information and update state. |
doctor | Check local configuration and live server connectivity. |
completion | Generate shell completion for supported shells. |
generate | Create local secrets, certificates, and API-key material. |
self-update | Check or apply a CLI update from the selected release channel. |
These commands make the CLI usable both as an operator tool and as a setup tool. For example, config and auth establish access before workload commands run, while doctor and version help separate a local CLI problem from a server problem.
References: cli/…/root.go• L21-30 cli/…/cmd.go• L26-31 cli/…/federated.go• L27-41 cli/…/cmd.go• L31-35 cli/…/cmd.go• L21-26 cli/…/cmd.go• L19-24 cli/…/cmd.go• L20-25 cli/…/cmd.go• L27-34 cli/…/cmd.go• L64-80
Command execution model
Every invocation follows the same broad path. The root command reads invocation-wide choices, creates a run context, and gives the selected command a path to the API and output services.
Invocation context
The invocation context is the shared runtime view of one command. It holds the loaded configuration plus the environment override, output mode, confirmation choice, color choice, and request timeout that apply only to that run.
The command then obtains either an authenticated client or an unauthenticated client. The first is used for normal product operations. The second supports actions such as device login and token exchange that must start before an access token exists.
This diagram shows how command input becomes a scoped API operation and terminal result.
flowchart LR
A[CLI arguments and flags] --> B[Root invocation setup]
B --> C[Run context]
C --> D[Authenticated or unauthenticated client]
D --> E[Environment-scoped API request]
E --> F[HTTP and API result checks]
F --> G[Text, JSON, stream, or error output]
The root setup also selects text or JSON output and configures logging before the command runs. The run-state service makes those choices available to code that creates a client later in the command path.
References: cli/main.go• L1-7 cli/…/root.go• L87-147 cli/…/context.go• L21-76 cli/…/context.go• L140-171 cli/…/state.go• L8-31 cli/…/context.go• L11-56
API client boundary
The API client is the boundary between command packages and the Arcane server. It builds requests from the configured server URL, applies the current authentication method, scopes environment-aware paths, and turns common server replies into usable command results.
The client accepts normal JSON requests and raw bodies for cases such as file upload. It understands the Arcane success envelope and rejects both failed HTTP status codes and API responses that report failure. It can refresh a JWT after an unauthorized response, and it retries only idempotent requests when a transport error or a retryable server status makes another attempt safe.
The client also provides a connection check against the version endpoint. This gives setup and diagnostic commands a small test that does not depend on a workload operation.
References: cli/…/client.go• L61-107 cli/…/client.go• L152-201 cli/…/client.go• L232-286 cli/…/client.go• L343-464 cli/…/client.go• L466-535 cli/…/client.go• L569-659
Resource reference resolution
Resource commands accept names or IDs when the product can identify the resource. A command first tries a direct lookup. If that does not identify one resource, it searches the relevant list and either selects the only match, asks the user to choose, or stops with an ambiguity error.
Interactive selection is available only when the terminal supports it. JSON and non-interactive runs do not guess between multiple resources, which keeps automation repeatable. Use a stable ID or a more precise name when a command reports ambiguity.
References: cli/…/cmd.go• L710-835 cli/…/cmd.go• L760-800 cli/…/cmd.go• L802-884 cli/…/cmd.go• L499-584 cli/…/cmd.go• L362-443 cli/…/cmd.go• L632-718 cli/…/prompt.go• L14-55
Configuration and authentication
The CLI separates durable connection settings from one-command choices. This lets a person keep a default server and environment while CI or a one-off operator command safely overrides them.
Persistent configuration
The default configuration file is ~/…/arcanecli.yml. It stores the server URL, one authentication form, the default environment, federated-auth audience, log level, update channel, and list settings. --config selects another file for the current invocation.
Configuration commands can create a starter file, set values, show masked credentials, test the server, and move the active file to a backup. Saving creates the private configuration directory and writes the file with private permissions. When API-key auth is selected, stored JWT and refresh tokens are cleared. When JWT auth is selected, the API key is cleared.
List limits use this order:
- A command-level
--limitvalue. - The resource-specific pagination setting.
- The global pagination setting.
- The command or server default.
An --env value changes the environment for one run without changing the saved default. ARCANE_TOKEN provides a short-lived JWT for the process and takes precedence over saved credentials.
References: cli/README.md• L26-55 cli/README.md• L62-93 cli/…/config.go• L81-107 cli/…/config.go• L139-185 cli/…/config.go• L188-250 cli/…/config.go• L82-167 cli/…/cmd.go• L37-96 cli/…/cmd.go• L100-149
Authentication flows
The CLI supports long-lived API-key access and browser-based OIDC login. Device login uses a short code, waits for the user to finish in a browser, then saves the returned access and refresh tokens. A later unauthorized API response can use the refresh token to renew access and update the saved token pair.
Federated login is the CI path. It accepts an external OIDC subject token from a flag, file, or standard input, or detects a token from GitHub Actions or GitLab. The CLI exchanges that token with Arcane for a short-lived bearer token. The caller can print shell exports for the current job, return JSON, or persist the token in the CLI config.
| Authentication mode | Best fit | Result |
|---|---|---|
| API key | Stable operator or service access | Sends an API-key header. |
| Device OIDC login | Interactive user access | Saves JWT and refresh tokens after browser approval. |
| Federated OIDC exchange | CI jobs | Produces a short-lived bearer token with optional export or persistence. |
References: cli/…/config.go• L84-129 cli/…/client.go• L455-535 cli/…/cmd.go• L33-169 cli/…/federated.go• L27-138 cli/…/ci_detect.go• L15-57
CI token detection
CI detection is a small provider layer used by federated authentication. In automatic mode it tries the GitHub Actions OIDC request endpoint first, then the GitLab job JWT source. A generic provider requires the caller to provide the token directly.
The detector returns both the token and its source label. That label reaches JSON and text output so a job can tell how its credential was obtained without parsing logs.
References: cli/…/ci_detect.go• L15-40 cli/…/ci_detect.go• L41-57 cli/…/ci_detect.go• L60-108 cli/…/federated.go• L140-173
Output and operator interaction
The CLI has one output contract for people and another for programs. Human output uses tables, status labels, progress views, and success messages. Machine output uses JSON and preserves the data needed by downstream scripts.
Text and JSON output
Text is the default mode. List commands present records in tables with totals, and detail commands present named values. The output service adapts colors to the terminal and can disable them with --no-color.
JSON is enabled with --output json or the --json alias. Commands return structured data instead of human status text. For paged lists, the response keeps the success, data, and pagination fields when the server supplies them, so callers can use both records and totals.
The response helpers enforce a successful HTTP status before decoding. This prevents a server error from being printed as a valid result. Failed actions return an error and do not print a success message.
References: cli/…/root.go• L97-127 cli/…/output.go• L86-155 cli/…/output.go• L165-238 cli/…/response.go• L16-95 cli/…/json_contract_test.go• L13-56 cli/…/action_error_handling_test.go• L17-79
Prompts and confirmations
Prompts protect destructive actions and resolve ambiguous names in an interactive terminal. A destructive command asks for confirmation and treats anything other than an affirmative answer as a cancellation. --yes skips the confirmation step for automation.
Selection prompts show a bounded set of matching resources. If standard input is not a terminal, the CLI returns a clear error instead of trying to read interactive input. JSON output also avoids interactive selection because it must remain suitable for scripts.
References: cli/…/prompt.go• L14-55 cli/…/confirm.go• L13-31 cli/…/context.go• L33-56 cli/…/cmd.go• L226-335
Progress and operation streams
Long actions use terminal feedback when text output is active. Image pulls and file transfers show progress, while project operations can return a line-oriented operation stream with raw work messages and a final error or completion signal.
JSON mode avoids progress decoration and passes structured or streamed server data to the caller. Long-running commands also use longer request limits where image pulls, uploads, project changes, or updates can take time.
References: cli/…/tui.go• L14-80 cli/…/tui.go• L82-169 cli/…/tui.go• L170-269 cli/…/cmd.go• L356-476 cli/…/cmd.go• L605-728 cli/…/cmd.go• L381-459
List and run-time contracts
Shared command helpers keep common wire behavior consistent across the many resource groups. These contracts matter when a command is used by scripts or when a server endpoint serves local and remote environments through the same API shape.
Pagination behavior
Paginated resources accept --limit, --start, and --all. The CLI sends these values as query parameters and keeps existing filters in the request. --all uses the server's return-everything sentinel and cannot be combined with explicit paging flags.
The resource name used for pagination is normalized before configuration lookup. This connects aliases such as singular resource names to the canonical per-resource setting. Project lists add archived records when --all is used because archived projects are otherwise hidden by default.
References: cli/…/pagination.go• L11-25 cli/…/pagination.go• L27-88 cli/…/config.go• L24-80 cli/…/config.go• L152-194 cli/…/pagination_test.go• L14-184 cli/…/pagination_test.go• L186-224
API response contracts
Most endpoints return an envelope with a success flag and a data value. List endpoints add paging information. A few endpoints return direct data or operation streams, so command groups choose the matching response form rather than forcing every result into one model.
The CLI keeps server fields that matter to callers when it can echo the raw JSON body. This is important for list metadata that a local display table does not show. Integration checks pin paths, query values, response shapes, and error behavior so a small contract drift does not silently break automation.
References: cli/…/client.go• L232-240 cli/…/client.go• L569-641 cli/…/response.go• L45-95 cli/…/cmd.go• L74-99 cli/…/json_contract_test.go• L13-56 cli/…/updates_commands_test.go• L14-70
Verification infrastructure
The CLI is checked at two levels. Go integration tests exercise the command tree against controlled HTTP servers, while Playwright tests run the built CLI against a live Arcane service and verify real product behavior.
Go command integration tests
The Go integration package invokes the exported root command with isolated temporary configuration. Its test server records requests and returns small API responses, which lets the suite verify CLI-to-server contracts without depending on a running deployment.
The tests cover JSON shape, pagination query construction, update filters, image update response types, missing arguments, and action errors. They also check that permission failures stop before success output and that --all is translated into the expected server request.
References: cli/…/command_helpers_test.go• L20-119 cli/…/json_contract_test.go• L13-56 cli/…/pagination_test.go• L14-384 cli/…/updates_commands_test.go• L14-459
End-to-end CLI tests
The Playwright CLI suite runs commands with a temporary config file and a test API key. It checks setup, diagnostics, version output, federated login, environment selection, workload reads, administrative CRUD, and JSON smoke coverage across the command groups.
The suite also models a remote edge environment. A read-only credential must receive 403 for a denied remote write, while an authorized credential reaches the disconnected agent and receives 502. This distinction verifies that access checks happen for the selected environment before the remote connection stage.
References: tests/…/cli.spec.ts• L51-69 tests/…/cli.spec.ts• L106-242 tests/…/cli.spec.ts• L244-527 tests/…/cli.spec.ts• L529-704
Dependency and runtime support
The CLI module defines the Go runtime and shared library boundary for command execution. Its direct dependencies provide command parsing, terminal presentation, structured logging, YAML configuration, Arcane types, and support for Docker and Compose-related behavior. The module also uses the local types module so CLI data models stay aligned with the repository's shared API types.
The module targets Go 1.27. Dependency checksums in go.sum lock the resolved module content for repeatable builds. Changes to these module files can affect terminal behavior, request models, config parsing, or build reproducibility even when command source files do not change.
| Dependency area | Runtime role |
|---|---|
| Cobra and pflag | Build the command tree and parse flags. |
| Charm terminal libraries | Render tables, prompts, progress views, colors, and terminal-aware interaction. |
Arcane types module | Share API and configuration data models with the rest of the product. |
| YAML support | Read and write the local CLI configuration. |
| Arcane support modules | Provide shared file-system, system, and byte-handling behavior used by commands. |
| Docker and Compose support | Support workload and project-related command behavior. |
| Test libraries | Support command integration and contract checks. |
References: cli/go.mod• L1-27 cli/go.mod• L29-89 cli/go.sum• L1-183
Change checklist
When these files or sections are changed, remember to consider these:
- Add a new command group to the root command registration so the executable can reach it.
- Keep command output mode, response envelope handling, and success or error exit behavior aligned with
cmdutiland the JSON integration contracts. - When adding a paged resource, update the canonical resource names and the server-side meaning of
--allbefore adding a config limit. - When changing authentication fields, preserve the rule that API-key and JWT credentials do not remain active together, and review
ARCANE_TOKENprecedence. - When changing an environment-aware endpoint, verify both local access and remote per-environment permission behavior.
- When changing a stream or transfer endpoint, review text progress, JSON pass-through, and the command timeout as one contract.
- When changing
cli/go.mod, review the affected command, terminal, model, configuration, or test contract and refreshcli/go.sumwith the same dependency resolution.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Server URL or authentication is missing | Normal API commands stop before sending a request. | Config.Validate requires a server URL and one auth method; config show exposes incomplete state. |
| An access token expires and refresh fails | The command returns an authentication error and does not claim success. | The client refreshes once when a refresh token exists, then saves the new pair only after a valid response. |
| A name matches more than one resource in a non-interactive run | The command fails instead of selecting an arbitrary resource. | Use a resource ID or a more precise reference. |
--all is combined with --limit or --start | The list request is rejected before it reaches the server. | Choose either all records or explicit paging. |
| The server returns a non-2xx status or a failed API envelope | No success output is printed and the command exits with an error. | Response helpers check HTTP status and API success before normal output. |
| A remote write lacks the selected environment permission | The server returns 403 before forwarding the action. | Use a credential with the required scoped grant. |
| An authorized remote action has no connected agent | The request reaches the remote boundary and returns 502. | Check edge-agent connectivity after the permission check passes. |
| A CI provider has no usable OIDC source | Federated authentication cannot mint or exchange a subject token. | Pass --token, --token-file, or --token-stdin, or provide the provider's expected CI variables. |
| A required Go module is unresolved or its checksum does not match | The CLI cannot build or the dependency update is rejected. | Keep go.mod and go.sum in sync and use the declared Go version. |
Key files
| File | Why to read it |
|---|---|
| cli/main.go | Shows the executable entry point. |
| cli/…/root.go | Shows root flags, runtime setup, and command registration. |
| cli/…/context.go | Defines the per-invocation context and client access. |
| cli/…/client.go | Defines the API boundary, auth, retries, refresh, and response checks. |
| cli/…/config.go | Defines local config loading, saving, initialization, and backups. |
| cli/…/config.go | Defines the durable config model and pagination rules. |
| cli/…/response.go | Defines shared status and JSON response handling. |
| cli/…/pagination.go | Defines list paging and the --all contract. |
| cli/…/output.go | Defines human-readable tables, status display, and color behavior. |
| cli/…/tui.go | Defines progress and stream-friendly terminal feedback. |
| cli/…/prompt.go | Defines interactive selection behavior. |
| cli/…/ci_detect.go | Defines CI OIDC token source detection. |
| cli/…/cmd.go | Illustrates a workload command group with actions and resource lookup. |
| cli/…/cmd.go | Illustrates project lifecycle actions, streams, and file input. |
| cli/…/cmd.go | Illustrates permission sets and scoped role assignments. |
| cli/…/federated.go | Illustrates CI token exchange and output choices. |
cli/go.mod | Defines the CLI's Go version and direct runtime, terminal, model, and test dependencies. |
cli/go.sum | Pins dependency checksums used for repeatable CLI builds. |
| cli/…/command_helpers_test.go | Shows isolated Go command execution against test configuration. |
| tests/…/cli.spec.ts | Shows live CLI product and remote-environment verification. |