@@ -8,17 +8,19 @@ import (
88 "time"
99
1010 "github.com/cenkalti/backoff/v4"
11+ "github.com/skratchdot/open-golang/open"
1112 "github.com/spf13/cobra"
1213 "github.com/treeverse/lakefs/pkg/api/apigen"
1314)
1415
1516const (
1617 // TODO(ariels): Underline the link?
17- webLoginTemplate = `Opening {{.RedirectURL|bold|blue}} where you should log in.
18-
19- If that URL does not open automatically, please open it manually and log in.
18+ webLoginTemplate = `Opening {{.RedirectURL | blue | underline}} where you should log in.
19+ If it does not open automatically, please try to open it manually and log in.
20+ `
21+ loggedInTemplate = `
22+ [{{.Time | green}}] {{"Logged in." | green | bold}}
2023`
21- loggedInTemplate = `Logged in as {{.Username}}.`
2224)
2325
2426type webLoginParams struct {
@@ -56,8 +58,11 @@ var loginCmd = &cobra.Command{
5658 redirectURL := serverURL .ResolveReference (relativeLocation )
5759
5860 Write (webLoginTemplate , webLoginParams {RedirectURL : redirectURL .String ()})
59- // TODO(ariels): Open redirectURL (xdg-open on Linux, something on MacOS, maybe
60- // a library does it?)
61+ err = open .Run (redirectURL .String ())
62+ if err != nil {
63+ Warning (fmt .Sprintf ("Failed to open URL: %s" , err .Error ()))
64+ // Keep going, user can manually use the URL.
65+ }
6166
6267 loginToken , err := backoff .RetryWithData (
6368 func () (* apigen.AuthenticationToken , error ) {
@@ -94,6 +99,8 @@ var loginCmd = &cobra.Command{
9499 if err != nil {
95100 DieErr (fmt .Errorf ("save login token: %w" , err ))
96101 }
102+
103+ Write (loggedInTemplate , struct { Time string }{Time : time .Now ().Format (time .DateTime )})
97104 },
98105}
99106
0 commit comments