Skip to content

Commit 98c9525

Browse files
authored
Also respect client flags in src login command (#480)
This wasn't respecting api flags. I also had to update the logic for retrieving the endpoint a bit, since it could have picked up a flag.
1 parent 3fdfb21 commit 98c9525

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

CHANGELOG.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,22 @@ All notable changes to `src-cli` are documented in this file.
1515

1616
### Changed
1717

18+
### Fixed
19+
20+
- The src login command now also properly respects the `-insecure-skip-verify` flag.
21+
22+
### Removed
23+
24+
## 3.25.2
25+
26+
### Changed
27+
1828
- The volume workspace Docker image is now only pulled if the volume workspace mode is in use. [#477](https://github.com/sourcegraph/src-cli/pull/477)
1929

2030
### Fixed
2131

2232
- Using volume workspace mode could result in Git errors when used with Docker containers that do not run as root. These have been fixed. [#478](https://github.com/sourcegraph/src-cli/issues/478)
2333

24-
### Removed
25-
2634
## 3.25.1
2735

2836
### Added

cmd/src/login.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"io/ioutil"
1010
"os"
1111
"strings"
12+
13+
"github.com/sourcegraph/src-cli/internal/api"
1214
)
1315

1416
func init() {
@@ -32,21 +34,28 @@ Examples:
3234
flagSet := flag.NewFlagSet("login", flag.ExitOnError)
3335
usageFunc := func() {
3436
fmt.Fprintln(flag.CommandLine.Output(), usage)
37+
flagSet.PrintDefaults()
3538
}
3639

40+
var (
41+
apiFlags = api.NewFlags(flagSet)
42+
)
43+
3744
handler := func(args []string) error {
3845
if err := flagSet.Parse(args); err != nil {
3946
return err
4047
}
4148
endpoint := cfg.Endpoint
42-
if len(args) == 1 {
43-
endpoint = args[0]
49+
if flagSet.NArg() >= 1 {
50+
endpoint = flagSet.Arg(0)
4451
}
4552
if endpoint == "" {
4653
return &usageError{errors.New("expected exactly one argument: the Sourcegraph URL, or SRC_ENDPOINT to be set")}
4754
}
4855

49-
return loginCmd(context.Background(), cfg, endpoint, os.Stdout)
56+
client := cfg.apiClient(apiFlags, ioutil.Discard)
57+
58+
return loginCmd(context.Background(), cfg, client, endpoint, os.Stdout)
5059
}
5160

5261
commands = append(commands, &command{
@@ -58,7 +67,7 @@ Examples:
5867

5968
var exitCode1 = &exitCodeError{exitCode: 1}
6069

61-
func loginCmd(ctx context.Context, cfg *config, endpointArg string, out io.Writer) error {
70+
func loginCmd(ctx context.Context, cfg *config, client api.Client, endpointArg string, out io.Writer) error {
6271
endpointArg = cleanEndpoint(endpointArg)
6372

6473
printProblem := func(problem string) {
@@ -97,7 +106,6 @@ func loginCmd(ctx context.Context, cfg *config, endpointArg string, out io.Write
97106
var result struct {
98107
CurrentUser *struct{ Username string }
99108
}
100-
client := cfg.apiClient(nil, ioutil.Discard)
101109
if _, err := client.NewRequest(query, nil).Do(ctx, &result); err != nil {
102110
if strings.HasPrefix(err.Error(), "error: 401 Unauthorized") || strings.HasPrefix(err.Error(), "error: 403 Forbidden") {
103111
printProblem("Invalid access token.")

cmd/src/login_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7+
"io/ioutil"
78
"net/http"
89
"net/http/httptest"
910
"strings"
@@ -15,7 +16,7 @@ func TestLogin(t *testing.T) {
1516
t.Helper()
1617

1718
var out bytes.Buffer
18-
err = loginCmd(context.Background(), cfg, endpointArg, &out)
19+
err = loginCmd(context.Background(), cfg, cfg.apiClient(nil, ioutil.Discard), endpointArg, &out)
1920
return strings.TrimSpace(out.String()), err
2021
}
2122

0 commit comments

Comments
 (0)