The section provides examples of various bash
commands to execute ld-find-code-refs
(when installed in the system PATH) with various configurations. We recommend reading through the following examples to gain an understanding of common configurations. For more information on advanced configuration, see CONFIGURATION.md
ld-find-code-refs \
--accessToken=$YOUR_LAUNCHDARKLY_ACCESS_TOKEN \ # example: api-xxxx
--projKey=$YOUR_LAUNCHDARKLY_PROJECT_KEY \ # example: my-project
--repoName=$YOUR_REPOSITORY_NAME \ # example: my-repo
--dir="/path/to/git/repo"
https://docs.launchdarkly.com/home/code/code-references#configuring-context-lines
ld-find-code-refs \
--accessToken="$YOUR_LAUNCHDARKLY_ACCESS_TOKEN" \
--projKey="$YOUR_LAUNCHDARKLY_PROJECT_KEY" \
--repoName="$YOUR_REPOSITORY_NAME" \
--dir="/path/to/git/repo" \
--contextLines=3 # can be up to 5. If < 0, no source code will be sent to LD
A configuration with the the repoType
set to GitHub, and the repoUrl
set to a GitHub URL. We recommend configuring these parameters so LaunchDarkly is able to generate reference links to your source code:
ld-find-code-refs \
--accessToken="$YOUR_LAUNCHDARKLY_ACCESS_TOKEN" \
--projKey="$YOUR_LAUNCHDARKLY_PROJECT_KEY" \
--repoName="$YOUR_REPOSITORY_NAME" \
--dir="/path/to/git/repo" \
--contextLines=3 \
--repoType="github" \
--repoUrl="$YOUR_REPOSITORY_URL" # example: https://github.com/launchdarkly/ld-find-code-refs
By default, ld-find-code-refs
will attempt to infer repository metadata from a git configuration. If you are scanning a codebase with a version control system other than git, you must use the --revision
and --branch
options to manually provide information about your codebase.
ld-find-code-refs \
--accessToken=$YOUR_LAUNCHDARKLY_ACCESS_TOKEN \ # example: api-xxxx
--projKey=$YOUR_LAUNCHDARKLY_PROJECT_KEY \ # example: my-project
--repoName=$YOUR_REPOSITORY_NAME \ # example: my-repo
--dir="/path/to/git/repo" \
--revision="REPO_REVISION_STRING" \ # e.g. a version hash
--branch="dev"
When scanning a non-git repository, automatic branch garbage collection is disabled. The prune
sub-command may be used to manually delete code references for stale branches.
The following example instructs the prune
command to delete code references for the branches named "branch1" and "branch2":
ld-find-code-refs prune \
--accessToken=$YOUR_LAUNCHDARKLY_ACCESS_TOKEN \ # example: api-xxxx
--projKey=$YOUR_LAUNCHDARKLY_PROJECT_KEY \ # example: my-project
--repoName=$YOUR_REPOSITORY_NAME \ # example: my-repo
--dir="/path/to/git/repo" \
"branch1" "branch2"
Support for multiple projects is provided through the coderefs.yaml
configuration file. Starting directories for the project block are relative to the git root directory.
The below configuration is scanning the two different starting subdirectories for different LaunchDarkly projects. The first configuration block is looking for feature flags from the example-project
LaunchDarkly project. subdir/to/start
and is generating camel case based aliases. The second configuration block is looking for feature flags from the other-project
LaunchDarkly project, starting in the relative directory subdir/to/other
and generating snake case aliases.
projects:
- key: example-project
dir: subdir/to/start
aliases:
- type: camelcase
- key: other-project
dir: subdir/to/other
aliases:
- type: snake_case