Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

allow coder login for WSL #446

Merged
merged 4 commits into from
Oct 6, 2021
Merged

allow coder login for WSL #446

merged 4 commits into from
Oct 6, 2021

Conversation

arminaaki
Copy link
Contributor

Issue

coder login fails to open user's browser while running from Windows Subsystem for Linux.

$ coder login <coder_url>
/usr/bin/xdg-open: 869: www-browser: not found
/usr/bin/xdg-open: 869: links2: not found
/usr/bin/xdg-open: 869: elinks: not found
/usr/bin/xdg-open: 869: links: not found
/usr/bin/xdg-open: 869: lynx: not found
/usr/bin/xdg-open: 869: w3m: not found

Changes

  • allow coder login to work while running from WSL.
  • Detect if running in WSL by identifying microsoft in /proc/version file.
$ cat /proc/version
Linux version ....-Microsoft ([email protected]) (gcc version ... (GCC) ) #...-Microsoft ....

Copy link
Contributor

@greyscaled greyscaled left a comment

Choose a reason for hiding this comment

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

Code looks great to me, appreciate the extra log! Thanks for the contribution! 👍🏻

@@ -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 👍🏻

@greyscaled greyscaled requested a review from jawnsy September 24, 2021 02:05
@greyscaled greyscaled added the enhancement New feature or request label Sep 24, 2021

// isWSL determines if coder-cli is running within Windows Subsystem for Linux
func isWSL() (bool, error) {
if runtime.GOOS == "darwin" || runtime.GOOS == "windows" {
Copy link
Contributor

Choose a reason for hiding this comment

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

it looks like we should make use of constants that are already defined:

https://github.com/cdr/coder-cli/blob/582f213d183be7135e2fcf0e6f839ea320e6c2f3/internal/cmd/update.go#L37

we should add goosDarwin as a const as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your review. Updated!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This may resolve → #448

if wsl {
cmd = "cmd.exe"
args = []string{"/c", "start"}
url = strings.Replace(url, "&", "^&", -1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
url = strings.Replace(url, "&", "^&", -1)
url = strings.ReplaceAll(url, "&", "^&")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

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
Contributor Author

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 upstream pkg/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!

@deansheather deansheather merged commit 6640696 into coder:main Oct 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants