Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Commit6640696

Browse files
authored
allow coder login for WSL (#446)
* allow coder login for WSL (#1)Co-authored-by: Armin <arminaaki@users.noreply.github.com>* use constants for runtime.GOOS* update lint errorsCo-authored-by: Armin <arminaaki@users.noreply.github.com>
1 parent34d96a1 commit6640696

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

‎internal/cmd/login.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import (
44
"bufio"
55
"context"
66
"fmt"
7+
"io/ioutil"
78
"net/url"
9+
"os/exec"
10+
"runtime"
811
"strings"
912

1013
"github.com/pkg/browser"
@@ -66,7 +69,8 @@ func login(cmd *cobra.Command, workspaceURL *url.URL) error {
6669
q.Add("show_token","true")
6770
authURL.RawQuery=q.Encode()
6871

69-
iferr:=browser.OpenURL(authURL.String());err!=nil {
72+
iferr:=openURL(authURL.String());err!=nil {
73+
clog.LogWarn(err.Error())
7074
fmt.Printf("Open the following in your browser:\n\n\t%s\n\n",authURL.String())
7175
}else {
7276
fmt.Printf("Your browser has been opened to visit:\n\n\t%s\n\n",authURL.String())
@@ -113,3 +117,36 @@ func pingAPI(ctx context.Context, workspaceURL *url.URL, token string) error {
113117
}
114118
returnnil
115119
}
120+
121+
// isWSL determines if coder-cli is running within Windows Subsystem for Linux
122+
funcisWSL() (bool,error) {
123+
ifruntime.GOOS==goosDarwin||runtime.GOOS==goosWindows {
124+
returnfalse,nil
125+
}
126+
data,err:=ioutil.ReadFile("/proc/version")
127+
iferr!=nil {
128+
returnfalse,xerrors.Errorf("read /proc/version: %w",err)
129+
}
130+
returnstrings.Contains(strings.ToLower(string(data)),"microsoft"),nil
131+
}
132+
133+
// openURL opens the provided URL via user's default browser
134+
funcopenURL(urlstring)error {
135+
varcmdstring
136+
varargs []string
137+
138+
wsl,err:=isWSL()
139+
iferr!=nil {
140+
returnxerrors.Errorf("test running Windows Subsystem for Linux: %w",err)
141+
}
142+
143+
ifwsl {
144+
cmd="cmd.exe"
145+
args= []string{"/c","start"}
146+
url=strings.ReplaceAll(url,"&","^&")
147+
args=append(args,url)
148+
returnexec.Command(cmd,args...).Start()
149+
}
150+
151+
returnbrowser.OpenURL(url)
152+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp