CLI reference

Overview and global options

The command structure, the global options every command accepts and how the rc file fits in.

The CLI has two commands, init and collect, and a handful of global options that apply to both. Running npx user-flow without a command executes collect.

npx user-flow [command] [options]
CommandPurpose
initCreate or update .user-flowrc.json and scaffold an example flow or a GitHub workflow.
collectExecute user flows against a URL and persist the reports. This is the default command.

Global options#

OptionAliasTypeDefaultDescription
--help-hbooleanShow help for the CLI or for the given command.
--versionbooleanPrint the CLI version.
--rcPath-pstring./.user-flowrc.jsonPath to the rc file to read.
--verbose-vbooleanfalseLog details about the run, including the resolved configuration.
--interactive-ibooleantrue (false in CI)When false, prompts are skipped and the suggested value is used instead.

The rc file#

.user-flowrc.json is the single place for project defaults. It has two sections that mirror the two halves of a run:

.user-flowrc.json
{
  "collect": {
    "url": "https://coffee-cart.netlify.app/",
    "ufPath": "./user-flows",
    "configPath": "./lh-config.json",
    "serveCommand": "npm run serve",
    "awaitServeStdout": "Server available under"
  },
  "persist": {
    "outPath": "./measures",
    "format": ["html", "json"]
  }
}
PropertyTypeDescription
collect.urlstringThe URL the browser opens. Must start with http:// or https://.
collect.ufPathstringA folder of flows or a single flow file.
collect.configPathstringPath to a Lighthouse config file. See Lighthouse configuration.
collect.configobjectA Lighthouse config inlined into the rc file.
collect.serveCommandstringAn npm script that serves the application before measuring.
collect.awaitServeStdoutstringThe console output that signals the serve command is ready.
persist.outPathstringFolder for the reports. Created on demand.
persist.formatstring[]Any of html, json, md and stdout. See Report formats.

Precedence. Options given on the command line win over the rc file. Options set inside a flow file, such as a Lighthouse config in flowOptions, win over both for that flow.

Multiple rc files#

Because --rcPath is a global option you can keep several configurations side by side, for example one for local development and one for CI:

npx user-flow collect --rcPath .user-flowrc.ci.json

CLI modes#

The CLI adapts its defaults to the environment it runs in. It reads the CI environment variable to decide:

ModeDetected whenDefaults
DEFAULTCI is not setInteractive prompts, reports open automatically, html format.
CICI is true or 1 (set by GitHub Actions and most other CI services)--interactive false, --openReport false, --dryRun false.
SANDBOXCI is SANDBOX--verbose, --dryRun, --openReport false. Used by the CLI's own test suite.

In practice this means a plain npx user-flow does the right thing on a CI runner without extra flags, while the same command on a laptop opens the report for you.