@@ -2,14 +2,13 @@ package user
22
33import (
44 "fmt"
5- "os/exec"
6- "runtime"
75 "time"
86
97 "github.com/charmbracelet/huh"
108 apiClient "github.com/major-technology/cli/clients/api"
119 mjrToken "github.com/major-technology/cli/clients/token"
1210 "github.com/major-technology/cli/singletons"
11+ "github.com/major-technology/cli/utils"
1312 "github.com/spf13/cobra"
1413)
1514
@@ -31,7 +30,7 @@ func runLogin(cobraCmd *cobra.Command) error {
3130 return fmt .Errorf ("failed to start login: %w" , err )
3231 }
3332
34- if err := openBrowser (startResp .VerificationURI ); err != nil {
33+ if err := utils . OpenBrowser (startResp .VerificationURI ); err != nil {
3534 // ignore, failed to open browser
3635 }
3736 cobraCmd .Println ("Attempting to automatically open the SSO authorization page in your default browser." )
@@ -71,24 +70,6 @@ func runLogin(cobraCmd *cobra.Command) error {
7170 return nil
7271}
7372
74- // openBrowser opens the specified URL in the default browser
75- func openBrowser (url string ) error {
76- var execCmd * exec.Cmd
77-
78- switch runtime .GOOS {
79- case "linux" :
80- execCmd = exec .Command ("xdg-open" , url )
81- case "windows" :
82- execCmd = exec .Command ("rundll32" , "url.dll,FileProtocolHandler" , url )
83- case "darwin" :
84- execCmd = exec .Command ("open" , url )
85- default :
86- return fmt .Errorf ("unsupported platform" )
87- }
88-
89- return execCmd .Start ()
90- }
91-
9273// pollForToken polls POST /cli/login/poll until authenticated or timeout
9374func pollForToken (cobraCmd * cobra.Command , client * apiClient.Client , deviceCode string , interval int , expiresIn int ) (string , error ) {
9475 ticker := time .NewTicker (time .Duration (interval ) * time .Second )
0 commit comments