99 "os/user"
1010 "path/filepath"
1111 "strings"
12-
13- "github.com/pkg/errors"
1412)
1513
1614const usageText = `src is a tool that provides access to Sourcegraph instances.
@@ -26,6 +24,7 @@ Environment variables
2624
2725The 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
3130The commands are:
@@ -49,6 +48,7 @@ Use "src [command] -h" for more information about a command.
4948
5049var (
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" )
0 commit comments