-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Impl "web" subcommand for opening TreeMaker (#174)
* impl "web" subcommand for opening TreeMaker * fix windows * wsl用にブラウザで開きたいため * update help * update readme * nits
- Loading branch information
Showing
3 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"os/exec" | ||
"runtime" | ||
) | ||
|
||
var openFuncs = map[string]func(string) error{ | ||
"windows": openWebByWindows, | ||
"linux": openWebByLinux, | ||
"wsl": openWebByWSL, | ||
"darwin": openWebByMac, | ||
} | ||
|
||
func openWeb(url string, isWSL bool) error { | ||
runtimeOS := runtime.GOOS | ||
if isWSL { | ||
runtimeOS = "wsl" | ||
} | ||
|
||
openFunc, ok := openFuncs[runtimeOS] | ||
if !ok { | ||
return errors.New("That OS is not yet supported....") | ||
} | ||
return openFunc(url) | ||
} | ||
|
||
func openWebByWindows(url string) error { | ||
_, err := exec.Command("cmd.exe", "/c", "start", url).CombinedOutput() | ||
return err | ||
} | ||
|
||
func openWebByLinux(url string) error { | ||
// TODO: インタラクティブモードで開かれた場合どうするか。errはnil | ||
// 戻り値に返ってきてるっぽい | ||
_, err := exec.Command("xdg-open", url).CombinedOutput() | ||
return err | ||
} | ||
|
||
func openWebByWSL(url string) error { | ||
_, err := exec.Command("cmd.exe", "/c", "start", url).CombinedOutput() | ||
return err | ||
} | ||
|
||
func openWebByMac(url string) error { | ||
_, err := exec.Command("open", url).CombinedOutput() | ||
return err | ||
} |