@@ -26,6 +26,7 @@ Environment variables
2626
2727The 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
3132The commands are:
@@ -49,6 +50,7 @@ Use "src [command] -h" for more information about a command.
4950
5051var (
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" )
0 commit comments