Overview
The WireMock CLI offers ways to get benefits of WireMock Cloud that are hard or impossible to achieve using the web interface.Installation
You can install the WireMock CLI using npm:Usage
A list of available commands can be found as follows:Setting command options
Most commands provided by the WireMock CLI take options that control how the command is executed. For example, therecord-many
command can take a --request-log-level
option like so:
record-many
command with a default set of option values, it would
be simpler to persist these values somewhere that the CLI could read without having to type them into the terminal
every time.
Another use case where writing values on the command line is problematic is when sensitive data is contained within
option values.
For options that commonly take sensitive data, the WireMock CLI will revert to prompting you for the option value via
stdin (if it’s not provided directly on the command line), but interactive prompting is not possible on non-interactive
terminals.
For the cases where providing option values via the command line is not desirable, it is possible to set command
options via environment variables and/or in a values file:
Environment variables
All CLI options (except for helper options like--help
) can be specified via environment variables.
The name of the environment variable always follows the pattern WMC_<SUBCOMMAND_NAME>_<OPTION_NAME>
where
<SUBCOMMAND_NAME>
is the name of the subcommand, that the option is relevant to, and <OPTION_NAME>
is the name of
the option itself.
Note that all dashes (-
) are replaced by underscores (_
).
For example,
wiremock mock-apis list
, delimit their subcommand names with underscores
(_
), like so:
--watch
option of wiremock push open-api
, can be specified via a boolean value.
For example,
Values file
All CLI options (except for helper options like--help
) can be specified within a YAML values file.
Option values must be provided as nested fields within their respective subcommand objects.
Note that all dashes (-
) are replaced by underscores (_
).
For example, consider the following values file:
wiremock record-many
with this values file is equivalent to
.wiremock/config.yaml
within the working
directory that the command was executed in.
This path can be overridden by setting the environment variable WMC_VALUES_CONFIG_FILE
to a custom file path.
Note that setting the
--wiremock-dir
option on commands such as record-many
will not affect where the CLI will
search for the default values file.wiremock mock-apis list
, are nested like so:
--watch
option of wiremock push open-api
, can be specified via a boolean value.
For example,
Precedence
Providing options via the command line, environment variables and a values files can be used interchangeably and mixed. Option values provided via the command line take precedence over those provided via environment variables, which in turn take precedence over those specified in the values file.Current Commands
Login
Most commands require you to have authenticated with WireMock Cloud. You can achieve this by running:If you have set your API endpoint to a custom endpoint,
wiremock login
will no longer work, so setting your API token using the config
subcommand is the only available method for authenticating.