File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed
Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -74,17 +74,35 @@ func cloneSite(ctx context.Context, args []string) error {
7474
7575 }
7676 if Serve {
77- cmd := exec . Command ( " open" , "http://localhost:5000" )
77+ cmd := open ( "http://localhost:5000" )
7878 if err := cmd .Start (); err != nil {
7979 return fmt .Errorf ("%v: %w" , cmd .Args , err )
8080 }
8181 return server .Serve (firstProject )
8282 } else if Open {
8383 // automatically open project
84- cmd := exec . Command ("open" , firstProject + "/index.html" )
84+ cmd := open ("open" , firstProject + "/index.html" )
8585 if err := cmd .Start (); err != nil {
8686 return fmt .Errorf ("%v: %w" , cmd .Args , err )
8787 }
8888 }
8989 return nil
9090}
91+
92+ // open opens the specified URL in the default browser of the user.
93+ func open (url string ) * exec.Cmd {
94+ var cmd string
95+ var args []string
96+
97+ switch runtime .GOOS {
98+ case "windows" :
99+ cmd = "cmd"
100+ args = []string {"/c" , "start" }
101+ case "darwin" :
102+ cmd = "open"
103+ default : // "linux", "freebsd", "openbsd", "netbsd"
104+ cmd = "xdg-open"
105+ }
106+ args = append (args , url )
107+ return exec .Command (cmd , args ... )
108+ }
You can’t perform that action at this time.
0 commit comments