Skip to content

Commit f183a79

Browse files
authored
Merge branch 'master' into validate_instance_cmd
2 parents 883f117 + 67b3ad9 commit f183a79

20 files changed

+1203
-362
lines changed

DEVELOPMENT.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
## Development
2+
3+
If you want to develop the CLI, clone the repository and build/install it with `go install`
4+
5+
```
6+
cd src-cli/
7+
go install ./cmd/src
8+
```
9+
10+
## Releasing
11+
12+
1. Find the latest version (either via the releases tab on GitHub or via git tags) to determine which version you are releasing.
13+
2. `VERSION=9.9.9 ./release.sh` (replace `9.9.9` with the version you are releasing)
14+
3. Travis will automatically perform the release. Once it has finished, **confirm that the curl commands fetch the latest version above**.
15+
4. Update the `MinimumVersion` constant in the [src-cli package](https://github.com/sourcegraph/sourcegraph/tree/master/internal/src-cli/consts.go).
16+
17+
### Patch releases
18+
19+
If a backwards-compatible change is made _after_ a backwards-incompatible one, the backwards-compatible one should be re-released to older instances that support it.
20+
21+
A Sourcegraph instance returns the highest patch version with the same major and minor version as `MinimumVersion` as defined in the instance. Patch versions are reserved solely for non-breaking changes and minor bug fixes. This allows us to dynamically release fixes for older versions of `src-cli` without having to update the instance.
22+
23+
To release a bug fix or a new feature that is backwards compatible with one of the previous two minor version of Sourcegraph, cherry-pick the changes into a patch branch and re-releases with a new patch version.
24+
25+
For example, suppose we have the the recommended versions.
26+
27+
| Sourcegraph version | Recommended src-cli version |
28+
| ------------------- | --------------------------- |
29+
| `3.100` | `3.90.5` |
30+
| `3.99` | `3.85.7` |
31+
32+
If a new feature is added to a new `3.91.6` release of src-cli and this change requires only features available in Sourcegraph `3.99`, then this feature should also be present in a new `3.85.8` release of src-cli. Because a Sourcegraph instance will automatically select the highest patch version, all non-breaking changes should increment only the patch version.
33+
34+
Note that if instead the recommended src-cli version for Sourcegraph `3.99` was `3.90.4` in the example above, there is no additional step required, and the new patch version of src-cli will be available to both Sourcegraph versions.

README.md

Lines changed: 58 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,186 +1,117 @@
1-
# Sourcegraph CLI [![Build Status](https://travis-ci.org/sourcegraph/src-cli.svg)](https://travis-ci.org/sourcegraph/src-cli) [![Go Report Card](https://goreportcard.com/badge/sourcegraph/src-cli)](https://goreportcard.com/report/sourcegraph/src-cli)
1+
# [Sourcegraph](https://sourcegraph.com) CLI [![Build Status](https://travis-ci.org/sourcegraph/src-cli.svg)](https://travis-ci.org/sourcegraph/src-cli) [![Go Report Card](https://goreportcard.com/badge/sourcegraph/src-cli)](https://goreportcard.com/report/sourcegraph/src-cli)
22

3-
<img src="https://user-images.githubusercontent.com/3173176/43567326-3db5f31c-95e6-11e8-9e74-4c04079c01b0.png" width=450 align=right>
3+
<img src="https://user-images.githubusercontent.com/3173176/43567326-3db5f31c-95e6-11e8-9e74-4c04079c01b0.png" width=500 align=right>
44

5-
**Quick links**:
6-
- [Installation](#installation)
7-
- [Setup](#setup) ([Authentication](#authentication))
8-
- [Usage](#usage)
5+
`src` is a command line interface to Sourcegraph:
96

10-
The Sourcegraph `src` CLI provides access to [Sourcegraph](https://sourcegraph.com) via a command-line interface.
7+
- **Search & get results in your terminal**
8+
- **Search & get JSON** for programmatic consumption
9+
- Make **GraphQL API requests** with auth easily & get JSON back fast
10+
- Execute **[campaign actions](https://docs.sourcegraph.com/user/campaigns)**
11+
- **Manage & administrate** repositories, users, and more
12+
- **Easily convert src-CLI commands to equivalent curl commands**, just add --get-curl!
1113

12-
It currently provides the ability to:
13-
14-
- **Execute search queries** from the command line and get nice colorized output back (or JSON, optionally).
15-
- **Execute GraphQL queries** against a Sourcegraph instance, and get JSON results back (`src api`).
16-
- You can provide your API access token via an environment variable or file on disk.
17-
- You can easily convert a `src api` command into a curl command with `src api -get-curl`.
18-
- **Manage repositories, users, and organizations** using the `src repos`, `src users`, and `src orgs` commands.
19-
- **Execute campaign actions** as part of [Sourcegraph campaigns](https://docs.sourcegraph.com/user/campaigns)
20-
21-
If there is something you'd like to see Sourcegraph be able to do from the CLI, let us know! :)
14+
**Note:** Using Sourcegraph 3.12 or earlier? [See the older README](https://github.com/sourcegraph/src-cli/tree/3.11.2).
2215

2316
## Installation
2417

25-
For Sourcegraph 3.13 and newer, the preferred method of installation is to ask _your_ Sourcegraph instance for the latest compatible version. To do this, replace `https://sourcegraph.com` in the commands below with the address of your instance.
26-
27-
For Sourcegraph 3.12 and older, run the following commands verbatim (against sourcegraph.com) or install from one of the published [releases on GitHub](https://github.com/sourcegraph/src-cli/releases).
28-
29-
```
30-
https://github.com/sourcegraph/src-cli/releases/download/{version}/{binary}
31-
```
18+
Binary downloads are available on the [releases tab](https://github.com/sourcegraph/src-cli/releases), and through Sourcegraph.com. _If the latest version does not work for you,_ consider using the version compatible with your Sourcegraph instance instead.
3219

33-
#### Requirements
20+
### Installation: Mac OS
3421

35-
If you want to use the `src action exec` functionality (see [Sourcegraph campaigns](https://docs.sourcegraph.com/user/campaigns) docs and `src action exec -h`), make sure that `git` is installed and accessible by `src`.
36-
37-
#### Mac OS
22+
#### Latest version
3823

3924
```bash
40-
# Sourcraph 3.13 and newer:
41-
curl -L https://<your-sourcegraph-instance>/.api/src-cli/src_darwin_amd64 -o /usr/local/bin/src
42-
chmod +x /usr/local/bin/src
43-
44-
# Sourcraph 3.12 and older:
4525
curl -L https://sourcegraph.com/.api/src-cli/src_darwin_amd64 -o /usr/local/bin/src
4626
chmod +x /usr/local/bin/src
4727
```
4828

49-
or use `brew` to get the newest version:
29+
or
5030

51-
```
31+
```bash
5232
brew install sourcegraph/src-cli/src-cli
5333
```
5434

55-
#### Linux
35+
#### Version compatible with your Sourcegraph instance
5636

57-
```bash
58-
# Sourcraph 3.13 and newer:
59-
curl -L https://<your-sourcegraph-instance>/.api/src-cli/src_linux_amd64 -o /usr/local/bin/src
60-
chmod +x /usr/local/bin/src
37+
Replace `sourcegraph.example.com` with your Sourcegraph instance URL:
6138

62-
# Sourcraph 3.12 and older:
63-
curl -L https://sourcegraph.com/.api/src-cli/src_linux_amd64 -o /usr/local/bin/src
39+
```bash
40+
curl -L https://sourcegraph.example.com/.api/src-cli/src_darwin_amd64 -o /usr/local/bin/src
6441
chmod +x /usr/local/bin/src
6542
```
6643

67-
#### Windows
68-
69-
**NOTE:** Windows support is still rough around the edges, but is available. If you encounter issues, please let us know by filing an issue :)
70-
71-
Run in PowerShell as administrator:
44+
### Installation: Linux
7245

73-
```powershell
74-
New-Item -ItemType Directory 'C:\Program Files\Sourcegraph'
46+
#### Latest version
7547

76-
# Sourcegraph 3.13 and newer:
77-
Invoke-WebRequest https://<your-sourcegraph-instance>/.api/src-cli/src_windows_amd64.exe -OutFile 'C:\Program Files\Sourcegraph\src.exe'
78-
# Sourcegraph 3.12 and older:
79-
Invoke-WebRequest https://sourcegraph.com/.api/src-cli/src_windows_amd64.exe -OutFile 'C:\Program Files\Sourcegraph\src.exe'
80-
81-
[Environment]::SetEnvironmentVariable('Path', [Environment]::GetEnvironmentVariable('Path', [EnvironmentVariableTarget]::Machine) + ';C:\Program Files\Sourcegraph', [EnvironmentVariableTarget]::Machine)
82-
$env:Path += ';C:\Program Files\Sourcegraph'
48+
```bash
49+
curl -L https://sourcegraph.com/.api/src-cli/src_linux_amd64 -o /usr/local/bin/src
50+
chmod +x /usr/local/bin/src
8351
```
8452

85-
Or manually:
86-
87-
- Download the latest src_windows_amd64.exe:
88-
- Sourcegraph 3.13 and newer: https://<your-sourcegraph-instance>/.api/src-cli/src_windows_amd64.exe
89-
- Sourcegraph 3.12 and older: https://sourcegraph.com/.api/src-cli/src_windows_amd64.exe
90-
- Place the file under e.g. `C:\Program Files\Sourcegraph\src.exe`
91-
- Add that directory to your system path to access it from any command prompt
53+
#### Version compatible with your Sourcegraph instance
9254

93-
#### Renaming `src` (optional)
55+
Replace `sourcegraph.example.com` with your Sourcegraph instance URL:
9456

95-
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:
96-
97-
```sh
98-
mv /usr/local/bin/src /usr/local/bin/sourcegraph-cli
57+
```bash
58+
curl -L https://sourcegraph.example.com/.api/src-cli/src_linux_amd64 -o /usr/local/bin/src
59+
chmod +x /usr/local/bin/src
9960
```
10061

101-
You can then invoke it via `sourcegraph-cli`.
62+
### Installation: Windows
10263

103-
## Setup
64+
See [Sourcegraph CLI for Windows](WINDOWS.md).
10465

105-
To use `src` with your own Sourcegraph instance set the `SRC_ENDPOINT` environment variable:
66+
## Setup with your Sourcegraph instance
10667

107-
```sh
108-
SRC_ENDPOINT=https://sourcegraph.example.com src search
109-
```
68+
### Via environment variables
11069

111-
Or via the configuration file (`~/src-config.json`):
70+
Point `src` to your instance and access token using environment variables:
11271

11372
```sh
114-
{"endpoint": "https://sourcegraph.example.com"}
73+
SRC_ENDPOINT=https://sourcegraph.example.com SRC_ACCESS_TOKEN="secret" src search 'foobar'
11574
```
11675

117-
### Authentication
76+
### Via global configuration file
11877

119-
Some Sourcegraph instances will be configured to require authentication. You can do so via the environment variable `SRC_ACCESS_TOKEN`:
78+
Create a `$HOME/src-config.json` with:
12079

12180
```sh
122-
SRC_ENDPOINT=https://sourcegraph.example.com SRC_ACCESS_TOKEN="secret" src ...
81+
{"endpoint": "https://sourcegraph.example.com", "accessToken": "secret"}
12382
```
12483

125-
Or via the configuration file (`~/src-config.json`):
84+
Then `src search 'foobar'` and other commands will automatically use that configuration!
12685

127-
```sh
128-
{"accessToken": "secret", "endpoint": "https://sourcegraph.example.com"}
129-
```
86+
### Where to get an access token
13087

131-
See `src -h` for more information on specifying access tokens.
132-
133-
To acquire the access token, 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.
88+
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.
13489

13590
## Usage
13691

13792
`src` provides different subcommands to interact with different parts of Sourcegraph:
13893

139-
- `search` - search for results on the configured Sourcegraph instance
140-
- `api` - interacts with the Sourcegraph GraphQL API
141-
- `repos` (alias: `repo`) - manages repositories
142-
- `users` (alias: `user`) - manages users
143-
- `orgs` (alias: `org`) - manages organizations
144-
- `config` - manages global, org, and user settings
145-
- `extsvc` - manages external services
146-
- `extensions` (alias: `ext`) - manages extensions
147-
- `actions` - runs [campaign actions](https://docs.sourcegraph.com/user/campaigns/actions)to generate patch sets
148-
- `campaigns` - manages [campaigns](https://docs.sourcegraph.com/user/campaigns)
149-
- `lsif` - manages LSIF data
150-
- `version` - display and compare the src-cli version against the recommended version of the configured Sourcegraph instance
94+
- `src search` - perform searches and get results in your terminal or as JSON
95+
- `src actions` - run [campaign actions](https://docs.sourcegraph.com/user/campaigns/actions) to generate patch sets
96+
- `src api` - run Sourcegraph GraphQL API requests
97+
- `src campaigns` - manages [campaigns](https://docs.sourcegraph.com/user/campaigns)
98+
- `src repos` - manage repositories
99+
- `src users` - manage users
100+
- `src orgs` - manages organization
101+
- `src config` - manage global, org, and user settings
102+
- `src extsvc` - manage external services (repository configuration)
103+
- `src extensions` - manage extensions
104+
- `src lsif` - manages LSIF data
105+
- `src version` - check version and guaranteed-compatible version for your Sourcegraph instance
151106

152107
Run `src -h` and `src <subcommand> -h` for more detailed usage information.
153108

154-
## Development
109+
#### Optional: Renaming `src`
155110

156-
If you want to develop the CLI, you can install it with `go get`:
111+
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:
157112

113+
```sh
114+
mv /usr/local/bin/src /usr/local/bin/src-cli
158115
```
159-
go get -u github.com/sourcegraph/src-cli/cmd/src
160-
```
161-
162-
## Releasing
163-
164-
1. Find the latest version (either via the releases tab on GitHub or via git tags) to determine which version you are releasing.
165-
2. `VERSION=9.9.9 ./release.sh` (replace `9.9.9` with the version you are releasing)
166-
3. Travis will automatically perform the release. Once it has finished, **confirm that the curl commands fetch the latest version above**.
167-
4. Update the `MinimumVersion` constant in the [src-cli package](https://github.com/sourcegraph/sourcegraph/tree/master/internal/src-cli/consts.go).
168-
169-
### Patch releases
170-
171-
If a backwards-compatible change is made _after_ a backwards-incompatible one, the backwards-compatible one should be re-released to older instances that support it.
172-
173-
A Sourcegraph instance returns the highest patch version with the same major and minor version as `MinimumVersion` as defined in the instance. Patch versions are reserved solely for non-breaking changes and minor bug fixes. This allows us to dynamically release fixes for older versions of `src-cli` without having to update the instance.
174-
175-
To release a bug fix or a new feature that is backwards compatible with one of the previous two minor version of Sourcegraph, cherry-pick the changes into a patch branch and re-releases with a new patch version.
176-
177-
For example, suppose we have the the recommended versions.
178-
179-
| Sourcegraph version | Recommended src-cli version |
180-
| ------------------- | --------------------------- |
181-
| `3.100` | `3.90.5` |
182-
| `3.99` | `3.85.7` |
183-
184-
If a new feature is added to a new `3.91.6` release of src-cli and this change requires only features available in Sourcegraph `3.99`, then this feature should also be present in a new `3.85.8` release of src-cli. Because a Sourcegraph instance will automatically select the highest patch version, all non-breaking changes should increment only the patch version.
185116

186-
Note that if instead the recommended src-cli version for Sourcegraph `3.99` was `3.90.4` in the example above, there is no additional step required, and the new patch version of src-cli will be available to both Sourcegraph versions.
117+
You can then invoke it via `src-cli`.

WINDOWS.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Sourcegraph CLI for Windows
2+
3+
**Note:** Windows support is still rough around the edges. If you encounter issues, please let us know by filing an issue.
4+
5+
## Installation
6+
7+
### Latest version
8+
9+
### Install via PowerShell
10+
11+
Run in PowerShell as administrator:
12+
13+
```powershell
14+
New-Item -ItemType Directory 'C:\Program Files\Sourcegraph'
15+
16+
Invoke-WebRequest https://sourcegraph.com/.api/src-cli/src_windows_amd64.exe -OutFile 'C:\Program Files\Sourcegraph\src.exe'
17+
18+
[Environment]::SetEnvironmentVariable('Path', [Environment]::GetEnvironmentVariable('Path', [EnvironmentVariableTarget]::Machine) + ';C:\Program Files\Sourcegraph', [EnvironmentVariableTarget]::Machine)
19+
$env:Path += ';C:\Program Files\Sourcegraph'
20+
```
21+
22+
#### Install manually
23+
24+
1. Download the latest [src_windows_amd64.exe](https://sourcegraph.com/.api/src-cli/src_windows_amd64.exe)
25+
2. Place the file under e.g. `C:\Program Files\Sourcegraph\src.exe`
26+
3. Add that directory to your system PATH to access it from any command prompt
27+
28+
### Version compatible with your Sourcegraph instance
29+
30+
### Install via PowerShell
31+
32+
Run in PowerShell as administrator, but replace `sourcegraph.example.com` with your Sourcegraph instance URL:
33+
34+
```powershell
35+
New-Item -ItemType Directory 'C:\Program Files\Sourcegraph'
36+
37+
Invoke-WebRequest https://sourcegraph.example.com/.api/src-cli/src_windows_amd64.exe -OutFile 'C:\Program Files\Sourcegraph\src.exe'
38+
39+
[Environment]::SetEnvironmentVariable('Path', [Environment]::GetEnvironmentVariable('Path', [EnvironmentVariableTarget]::Machine) + ';C:\Program Files\Sourcegraph', [EnvironmentVariableTarget]::Machine)
40+
$env:Path += ';C:\Program Files\Sourcegraph'
41+
```
42+
43+
#### Install manually
44+
45+
1. Download the latest src_windows_amd64.exe from your Sourcegraph instance at e.g. https://sourcegraph.example.com/.api/src-cli/src_windows_amd64.exe (replace sourcegraph.example.com with your Sourcegraph instance URL)
46+
2. Place the file under e.g. `C:\Program Files\Sourcegraph\src.exe`
47+
3. Add that directory to your system PATH to access it from any command prompt

appveyor.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
version: "{build}"
2-
shallow_clone: true
32
clone_folder: c:\gopath\src\github.com\sourcegraph\src-cli
43
environment:
54
GOPATH: c:\gopath

0 commit comments

Comments
 (0)