Skip to content

Commit 8e6f1ee

Browse files
authored
Revert "Remove -endpoint flag (#225)" (#234)
* Revert "Remove -endpoint flag (#225)" This reverts commit a167443. This broke some existing users of src-cli. Another PR will make this a more graceful deprecation. * Remove unused package
1 parent 03d594b commit 8e6f1ee

File tree

3 files changed

+13
-176
lines changed

3 files changed

+13
-176
lines changed

CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,3 @@ All notable changes to `src-cli` are documented in this file.
2424
### Fixed
2525

2626
### Removed
27-
28-
- Remove the `-endpoint` flag. [#225](https://github.com/sourcegraph/src-cli/pull/225)

cmd/src/main.go

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99
"os/user"
1010
"path/filepath"
1111
"strings"
12-
13-
"github.com/pkg/errors"
1412
)
1513

1614
const usageText = `src is a tool that provides access to Sourcegraph instances.
@@ -26,6 +24,7 @@ Environment variables
2624
2725
The options are:
2826
27+
-endpoint= specifies the endpoint to use e.g. "https://sourcegraph.com" (overrides SRC_ENDPOINT if set)
2928
-v print verbose output
3029
3130
The commands are:
@@ -49,6 +48,7 @@ Use "src [command] -h" for more information about a command.
4948

5049
var (
5150
configPath = flag.String("config", "", "")
51+
endpoint = flag.String("endpoint", "", "")
5252
verbose = flag.Bool("v", false, "print verbose output")
5353
)
5454

@@ -76,14 +76,14 @@ func readConfig() (*config, error) {
7676
cfgPath := *configPath
7777
userSpecified := *configPath != ""
7878

79-
u, err := user.Current()
79+
user, err := user.Current()
8080
if err != nil {
8181
return nil, err
8282
}
8383
if !userSpecified {
84-
cfgPath = filepath.Join(u.HomeDir, "src-config.json")
84+
cfgPath = filepath.Join(user.HomeDir, "src-config.json")
8585
} else if strings.HasPrefix(cfgPath, "~/") {
86-
cfgPath = filepath.Join(u.HomeDir, cfgPath[2:])
86+
cfgPath = filepath.Join(user.HomeDir, cfgPath[2:])
8787
}
8888
data, err := ioutil.ReadFile(os.ExpandEnv(cfgPath))
8989
if err != nil && (!os.IsNotExist(err) || userSpecified) {
@@ -96,26 +96,17 @@ func readConfig() (*config, error) {
9696
}
9797
}
9898

99-
envToken := os.Getenv("SRC_ACCESS_TOKEN")
100-
envEndpoint := os.Getenv("SRC_ENDPOINT")
101-
102-
if userSpecified {
103-
// If a config file is present, either zero or both environment variables must be present.
104-
// We don't want to partially apply environment variables.
105-
if envToken == "" && envEndpoint != "" {
106-
return nil, errConfigMerge
107-
}
108-
if envToken != "" && envEndpoint == "" {
109-
return nil, errConfigMerge
110-
}
111-
}
112-
11399
// Apply config overrides.
114-
if envToken != "" {
100+
if envToken := os.Getenv("SRC_ACCESS_TOKEN"); envToken != "" {
115101
cfg.AccessToken = envToken
116102
}
117-
if envEndpoint != "" {
118-
cfg.Endpoint = envEndpoint
103+
if *endpoint != "" {
104+
cfg.Endpoint = *endpoint
105+
}
106+
if cfg.Endpoint == "" {
107+
if endpoint := os.Getenv("SRC_ENDPOINT"); endpoint != "" {
108+
cfg.Endpoint = endpoint
109+
}
119110
}
120111
if cfg.Endpoint == "" {
121112
cfg.Endpoint = "https://sourcegraph.com"
@@ -125,5 +116,3 @@ func readConfig() (*config, error) {
125116

126117
return &cfg, nil
127118
}
128-
129-
var errConfigMerge = errors.New("config merging not supported, zero or both environment variables must be set")

cmd/src/main_test.go

Lines changed: 0 additions & 150 deletions
This file was deleted.

0 commit comments

Comments
 (0)