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

allow coder login for WSL#446

Merged
deansheather merged 4 commits intocoder:mainfromarminaaki:main
Oct 6, 2021
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletioninternal/cmd/login.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,10 @@ import (
"bufio"
"context"
"fmt"
"io/ioutil"
"net/url"
"os/exec"
"runtime"
"strings"

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

if err := browser.OpenURL(authURL.String()); err != nil {
if err := openURL(authURL.String()); err != nil {
clog.LogWarn(err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks for the additional warning log 👍🏻

arminaaki reacted with hooray emoji
fmt.Printf("Open the following in your browser:\n\n\t%s\n\n", authURL.String())
} else {
fmt.Printf("Your browser has been opened to visit:\n\n\t%s\n\n", authURL.String())
Expand DownExpand Up@@ -113,3 +117,36 @@ func pingAPI(ctx context.Context, workspaceURL *url.URL, token string) error {
}
return nil
}

// isWSL determines if coder-cli is running within Windows Subsystem for Linux
func isWSL() (bool, error) {
if runtime.GOOS == goosDarwin || runtime.GOOS == goosWindows {
return false, nil
}
data, err := ioutil.ReadFile("/proc/version")
if err != nil {
return false, xerrors.Errorf("read /proc/version: %w", err)
}
return strings.Contains(strings.ToLower(string(data)), "microsoft"), nil
}

// openURL opens the provided URL via user's default browser
func openURL(url string) error {
var cmd string
var args []string

wsl, err := isWSL()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think this is good, but I do wonder whether we could propose this upstream to pkg/browser

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thank you for the review. I agree, this work should ideally be part of upstreampkg/browser. But Thoughts on moving forward with the work for Coder until I have the patch ready for upstream?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yeah, I think it makes sense to make this change now for sure! No objection to it :)

Thanks for your contribution!

if err != nil {
return xerrors.Errorf("test running Windows Subsystem for Linux: %w", err)
}

if wsl {
cmd = "cmd.exe"
args = []string{"/c", "start"}
url = strings.ReplaceAll(url, "&", "^&")
args = append(args, url)
return exec.Command(cmd, args...).Start()
}

return browser.OpenURL(url)
}

[8]ページ先頭

©2009-2025 Movatter.jp