Environment variables
About 608 words
unifi-cli reads a small number of environment variables. None of them is required.
unifi-cli's own
| Variable | Effect |
|---|---|
UNIFI_CONFIG | Path of the configuration file, instead of ~/.config/unifi-cli/config.yaml. The themes directory and the credentials file move with it, into the same directory. |
UNIFI_API_KEY | An API key that takes precedence over every stored key, for every account. unifi login also reads the key to store from it. |
UNIFI_LOG_LEVEL | Minimum level written to the log file for this run: debug, info, warn or error. It wins over preferences.log.level; an unrecognized value is ignored. |
UNIFI_CREDENTIAL_STORE | Where API keys are stored and looked up. auto (the default) uses the OS keychain and falls back to the credentials file when there is no keychain or it doesn't answer within three seconds; keyring uses only the keychain; file never touches the keychain. Any other value behaves like auto. |
UNIFI_NO_CACHE | Set to 1 to ask the controller for everything instead of using cached answers, like --no-cache on every command. |
UNIFI_API_KEY is read-only as a credential store: unifi logout can't remove it, and unifi ctx describe reports stored in the env credential store while it's set. Because it answers for every account, set it per command or per CI job, not in a shell profile.
UNIFI_CREDENTIAL_STORE=file is meant for headless machines, containers and tests, where a keychain is missing or shouldn't be touched. The credentials file sits next to the configuration file, so together with UNIFI_CONFIG it gives you a setup that is isolated from your own.
Directories
| Variable | Effect |
|---|---|
XDG_CONFIG_HOME | Base directory for configuration. The configuration directory becomes $XDG_CONFIG_HOME/unifi-cli. |
XDG_STATE_HOME | Base directory for state. The log, the shell history and the cache go to $XDG_STATE_HOME/unifi-cli. |
HOME | Fallback for both: ~/.config/unifi-cli and ~/.local/state/unifi-cli. |
UNIFI_CONFIG wins over XDG_CONFIG_HOME for everything that lives in the configuration directory. The defaults are the same on Linux, macOS and Windows.
Terminal and editor
| Variable | Effect |
|---|---|
VISUAL, EDITOR | The editor of unifi config edit and of edit on configuration subjects. VISUAL wins; the fallback is vi. An editor that returns at once needs its wait flag, as in EDITOR='code --wait'. |
COLUMNS, LINES | Override the detected terminal size. Set COLUMNS to get a fixed table width in scripts and logs. |
NO_COLOR | When set, output on a terminal has no colors. Bold is kept. |
CLICOLOR_FORCE | When set to 1, output keeps its colors in a pipe or a file. |
TERM, COLORTERM | Used to detect how many colors the terminal supports. |
Output to a pipe or a file has no colors unless CLICOLOR_FORCE says otherwise. Machine-readable output (--output json or yaml) never has colors.
The demo controller
These are read by unifi-mock, not by unifi:
| Variable | Effect |
|---|---|
UNIFI_MOCK_API_KEY | The full-access API key the mock accepts. Default demo-api-key. |
UNIFI_MOCK_READONLY_API_KEY | The read-only API key. Without it, demo-readonly-key is accepted only while the full-access key is the default. |
UNIFI_MOCK_DEMO_USER, UNIFI_MOCK_DEMO_PASSWORD, UNIFI_MOCK_DEMO_CODE | E-mail address, password and one-time code of the fake UI account under /cloud. The public defaults only work while the mock listens on a loopback address. |
Precedence
For a setting that can come from several places, the order is: command-line flag, then environment variable, then configuration file, then built-in default.
| Setting | Flag | Environment | Configuration |
|---|---|---|---|
| Context | --context | currentContext | |
| Site | --site | the context's site | |
| Output format | --output | preferences.output | |
| Theme | --theme | preferences.theme | |
| Color scheme | --color-scheme | preferences.colorScheme | |
| API key | UNIFI_API_KEY | the keychain, then the credentials file | |
| Log level | UNIFI_LOG_LEVEL | preferences.log.level | |
| Cache | --no-cache | UNIFI_NO_CACHE |
