Skip to content

Commit de21b85

Browse files
committed
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.
1 parent 0c602c1 commit de21b85

File tree

3 files changed

+13
-174
lines changed

3 files changed

+13
-174
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 & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Environment variables
2626
2727
The options are:
2828
29+
-endpoint= specifies the endpoint to use e.g. "https://sourcegraph.com" (overrides SRC_ENDPOINT if set)
2930
-v print verbose output
3031
3132
The commands are:
@@ -49,6 +50,7 @@ Use "src [command] -h" for more information about a command.
4950

5051
var (
5152
configPath = flag.String("config", "", "")
53+
endpoint = flag.String("endpoint", "", "")
5254
verbose = flag.Bool("v", false, "print verbose output")
5355
)
5456

@@ -76,14 +78,14 @@ func readConfig() (*config, error) {
7678
cfgPath := *configPath
7779
userSpecified := *configPath != ""
7880

79-
u, err := user.Current()
81+
user, err := user.Current()
8082
if err != nil {
8183
return nil, err
8284
}
8385
if !userSpecified {
84-
cfgPath = filepath.Join(u.HomeDir, "src-config.json")
86+
cfgPath = filepath.Join(user.HomeDir, "src-config.json")
8587
} else if strings.HasPrefix(cfgPath, "~/") {
86-
cfgPath = filepath.Join(u.HomeDir, cfgPath[2:])
88+
cfgPath = filepath.Join(user.HomeDir, cfgPath[2:])
8789
}
8890
data, err := ioutil.ReadFile(os.ExpandEnv(cfgPath))
8991
if err != nil && (!os.IsNotExist(err) || userSpecified) {
@@ -96,26 +98,17 @@ func readConfig() (*config, error) {
9698
}
9799
}
98100

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-
113101
// Apply config overrides.
114-
if envToken != "" {
102+
if envToken := os.Getenv("SRC_ACCESS_TOKEN"); envToken != "" {
115103
cfg.AccessToken = envToken
116104
}
117-
if envEndpoint != "" {
118-
cfg.Endpoint = envEndpoint
105+
if *endpoint != "" {
106+
cfg.Endpoint = *endpoint
107+
}
108+
if cfg.Endpoint == "" {
109+
if endpoint := os.Getenv("SRC_ENDPOINT"); endpoint != "" {
110+
cfg.Endpoint = endpoint
111+
}
119112
}
120113
if cfg.Endpoint == "" {
121114
cfg.Endpoint = "https://sourcegraph.com"
@@ -125,5 +118,3 @@ func readConfig() (*config, error) {
125118

126119
return &cfg, nil
127120
}
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)