Sourcegraph CLI
src
is a command line interface to Sourcegraph:
- Search & get results in your terminal
- Search & get JSON for programmatic consumption
- Make GraphQL API requests with auth easily & get JSON back fast
- Execute campaign actions
- Manage & administrate repositories, users, and more
- Easily convert src-CLI commands to equivalent curl commands, just add --get-curl!
Note: Using Sourcegraph 3.12 or earlier? See the older README.
Binary downloads are available on the releases tab, and through Sourcegraph.com. If the latest version does not work for you, consider using the version compatible with your Sourcegraph instance instead.
curl -L https://sourcegraph.com/.api/src-cli/src_darwin_amd64 -o /usr/local/bin/src
chmod +x /usr/local/bin/src
or
brew install sourcegraph/src-cli/src-cli
Replace sourcegraph.example.com
with your Sourcegraph instance URL:
curl -L https://sourcegraph.example.com/.api/src-cli/src_darwin_amd64 -o /usr/local/bin/src
chmod +x /usr/local/bin/src
curl -L https://sourcegraph.com/.api/src-cli/src_linux_amd64 -o /usr/local/bin/src
chmod +x /usr/local/bin/src
Replace sourcegraph.example.com
with your Sourcegraph instance URL:
curl -L https://sourcegraph.example.com/.api/src-cli/src_linux_amd64 -o /usr/local/bin/src
chmod +x /usr/local/bin/src
See Sourcegraph CLI for Windows.
Point src
to your instance and access token using environment variables:
SRC_ENDPOINT=https://sourcegraph.example.com SRC_ACCESS_TOKEN="secret" src search 'foobar'
Sourcegraph behind a custom auth proxy? See auth proxy configuration docs.
Visit your Sourcegraph instance (or https://sourcegraph.com), click your username in the top right to open the user menu, select Settings, and then select Access tokens in the left hand menu.
src
provides different subcommands to interact with different parts of Sourcegraph:
src search
- perform searches and get results in your terminal or as JSONsrc actions
- run campaign actions to generate patch setssrc api
- run Sourcegraph GraphQL API requestssrc campaigns
- manages campaignssrc repos
- manage repositoriessrc users
- manage userssrc orgs
- manages organizationsrc config
- manage global, org, and user settingssrc extsvc
- manage external services (repository configuration)src extensions
- manage extensionssrc lsif
- manages LSIF datasrc serve-git
- serves your local git repositories over HTTP for Sourcegraph to pullsrc version
- check version and guaranteed-compatible version for your Sourcegraph instance
Run src -h
and src <subcommand> -h
for more detailed usage information.
If you have a naming conflict with the src
command, such as a Bash alias, you can rename the static binary. For example, on Linux / Mac OS:
mv /usr/local/bin/src /usr/local/bin/src-cli
You can then invoke it via src-cli
.