@@ -54,20 +54,23 @@ Examples:
5454 if err := flagSet .Parse (args ); err != nil {
5555 return err
5656 }
57- endpoint := cfg . Endpoint
57+
5858 if flagSet .NArg () >= 1 {
59- endpoint = flagSet .Arg (0 )
60- }
61- if endpoint == "" {
62- return cmderrors .Usage ("expected exactly one argument: the Sourcegraph URL, or SRC_ENDPOINT to be set" )
59+ arg := flagSet .Arg (0 )
60+ parsed , err := parseEndpoint (arg )
61+ if err != nil {
62+ return cmderrors .Usage (fmt .Sprintf ("invalid endpoint URL: %s" , arg ))
63+ }
64+ if parsed .String () != cfg .endpointURL .String () {
65+ return cmderrors .Usage (fmt .Sprintf ("The configured endpoint is %s, not %s" , cfg .endpointURL , parsed ))
66+ }
6367 }
6468
6569 client := cfg .apiClient (apiFlags , io .Discard )
6670
6771 return loginCmd (context .Background (), loginParams {
6872 cfg : cfg ,
6973 client : client ,
70- endpoint : endpoint ,
7174 out : os .Stdout ,
7275 useOAuth : * useOAuth ,
7376 apiFlags : apiFlags ,
@@ -85,7 +88,6 @@ Examples:
8588type loginParams struct {
8689 cfg * config
8790 client api.Client
88- endpoint string
8991 out io.Writer
9092 useOAuth bool
9193 apiFlags * api.Flags
@@ -99,16 +101,15 @@ type loginFlowKind int
99101const (
100102 loginFlowOAuth loginFlowKind = iota
101103 loginFlowMissingAuth
102- loginFlowEndpointConflict
103104 loginFlowValidate
104105)
105106
106107var loadStoredOAuthToken = oauth .LoadToken
107108
108109func loginCmd (ctx context.Context , p loginParams ) error {
109- if p .cfg .ConfigFilePath != "" {
110+ if p .cfg .configFilePath != "" {
110111 fmt .Fprintln (p .out )
111- fmt .Fprintf (p .out , "⚠️ Warning: Configuring src with a JSON file is deprecated. Please migrate to using the env vars SRC_ENDPOINT, SRC_ACCESS_TOKEN, and SRC_PROXY instead, and then remove %s. See https://github.com/sourcegraph/src-cli#readme for more information.\n " , p .cfg .ConfigFilePath )
112+ fmt .Fprintf (p .out , "⚠️ Warning: Configuring src with a JSON file is deprecated. Please migrate to using the env vars SRC_ENDPOINT, SRC_ACCESS_TOKEN, and SRC_PROXY instead, and then remove %s. See https://github.com/sourcegraph/src-cli#readme for more information.\n " , p .cfg .configFilePath )
112113 }
113114
114115 _ , flow := selectLoginFlow (ctx , p )
@@ -117,28 +118,23 @@ func loginCmd(ctx context.Context, p loginParams) error {
117118
118119// selectLoginFlow decides what login flow to run based on flags and config.
119120func selectLoginFlow (ctx context.Context , p loginParams ) (loginFlowKind , loginFlow ) {
120- endpointArg := cleanEndpoint (p .endpoint )
121-
122121 if p .useOAuth {
123122 return loginFlowOAuth , runOAuthLogin
124123 }
125- if ! hasEffectiveAuth (ctx , p .cfg , endpointArg ) {
124+ if ! hasEffectiveAuth (ctx , p .cfg ) {
126125 return loginFlowMissingAuth , runMissingAuthLogin
127126 }
128- if endpointArg != p .cfg .Endpoint {
129- return loginFlowEndpointConflict , runEndpointConflictLogin
130- }
131127 return loginFlowValidate , runValidatedLogin
132128}
133129
134130// hasEffectiveAuth determines whether we have auth credentials to continue. It first checks for a resolved Access Token in
135131// config, then it checks for a stored OAuth token.
136- func hasEffectiveAuth (ctx context.Context , cfg * config , resolvedEndpoint string ) bool {
137- if cfg .AccessToken != "" {
132+ func hasEffectiveAuth (ctx context.Context , cfg * config ) bool {
133+ if cfg .accessToken != "" {
138134 return true
139135 }
140136
141- if _ , err := loadStoredOAuthToken (ctx , resolvedEndpoint ); err == nil {
137+ if _ , err := loadStoredOAuthToken (ctx , cfg . endpointURL . String () ); err == nil {
142138 return true
143139 }
144140
0 commit comments