LaunchDarkly CLI commands
Read time: 3 minutes
Last edited: Aug 28, 2024
Overview
This topic describes common commands and configuration options in the LaunchDarkly CLI.
View available commands
The majority of the LaunchDarkly CLI commands are resource commands. These commands provide direct access to LaunchDarkly APIs.
To view available commands:
ldcli
Set input and output formats
For each LaunchDarkly CLI resource command, you can use command line arguments, or use your shell to provide an input file.
For example, here's how to create a flag using data from the command line:
ldcli flags create --project default -d '{"name": "Example flag", "key": "example-flag"}'
Here's how to create the same flag using data from a file:
ldcli flags create --project default -d "$(cat data.json)"
By default, resource commands return a simplified plaintext output. For example, the default output message for creating the new flag in the example above is Successfully created Example flag (example-flag)
.
To view the full JSON response from any resource command, use the --output json
flag. Optionally, pipe the result through jq
for improved formatting. Here's how:
ldcli flags create --project default -d '{"name": "Example flag", "key": "example-flag"}' --output json | jq
If you prefer a particular output format, you can use the config
command to set that preference:
ldcli config --set output json # or plaintext
Access SDK credentials
You can access the SDK credentials for a specific project and environment using the environments
resource. You need different SDK credentials depending on which SDK you're working with. To learn more about SDK credentials, read Keys.
Here's how:
# use the SDK key for authorization in server-side SDKsldcli environments get --project <your project> --environment <your environment> | jq '.apiKey'
Use ldcli
for local development
The LaunchDarkly CLI includes a dev-server
command that you can use to start a local server, retrieve flag values from a LaunchDarkly source environment, and update those flag values locally. This means you can test your code locally, without having to coordinate with other developers in your organization who are using the same LaunchDarkly source environment.
To learn more, use ldcli dev-server --help
or read our guide, Using the LaunchDarkly CLI for local testing.
Find additional documentation
Use the ldcli [command] --help
command to view usage information for all commands for the LaunchDarkly CLI.
To view and contribute to the LaunchDarkly CLI source code, or to file issues for our team, visit the LaunchDarkly CLI GitHub repository.