Skip to content

Commit

Permalink
Add "ddev launch" command, fixes #910 (#1862)
Browse files Browse the repository at this point in the history
* Add DDEV_PRIMARY_URL and make accessible to commands
* Add 'ddev launch' command
  • Loading branch information
rfay committed Oct 20, 2019
1 parent c9b948a commit f9af3b6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cmd/ddev/cmd/commands.go
Expand Up @@ -108,9 +108,10 @@ func makeHostCmd(app *ddevapp.DdevApp, fullPath, name string) func(*cobra.Comman
osArgs = os.Args[2:]
}
var err error
// Load environment variables that may be useful for script.
app.DockerEnv()
if runtime.GOOS == "windows" {
// Sadly, not sure how to have a bash interpreter without this.
//bashPath := `C:\Program Files\Git\bin\bash.exe`
args := []string{fullPath}
args = append(args, osArgs...)
err = exec.RunInteractiveCommand(windowsBashPath, args)
Expand Down
17 changes: 17 additions & 0 deletions cmd/ddev/cmd/dotddev_assets/commands/host/launch
@@ -0,0 +1,17 @@
#!/bin/bash

## Description: Launch a browser with the current site
## Usage: launch
## Example: "ddev launch"

case $OSTYPE in
linux-gnu)
xdg-open ${DDEV_PRIMARY_URL}
;;
"darwin"*)
open ${DDEV_PRIMARY_URL}
;;
"win*"* | "msys"*)
start ${DDEV_PRIMARY_URL}
;;
esac
2 changes: 2 additions & 0 deletions cmd/ddev/cmd/packrd/packed-packr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions pkg/ddevapp/ddevapp.go
Expand Up @@ -1085,6 +1085,7 @@ func (app *DdevApp) DockerEnv() {
"DDEV_ROUTER_HTTP_PORT": app.RouterHTTPPort,
"DDEV_ROUTER_HTTPS_PORT": app.RouterHTTPSPort,
"DDEV_XDEBUG_ENABLED": strconv.FormatBool(app.XdebugEnabled),
"DDEV_PRIMARY_URL": app.GetPrimaryURL(),
}

// Set the mariadb_local command to empty to prevent docker-compose from complaining normally.
Expand Down Expand Up @@ -1459,6 +1460,15 @@ func (app *DdevApp) GetAllURLs() (httpURLs []string, httpsURLs []string, allURLs
return httpURLs, httpsURLs, append(httpURLs, httpsURLs...)
}

// GetPrimaryURL() returns the primary URL that can be used, https or http
func (app *DdevApp) GetPrimaryURL() string {
httpURLs, urlList, _ := app.GetAllURLs()
if GetCAROOT() == "" {
urlList = httpURLs
}
return urlList[0]
}

// GetWebContainerDirectHTTPURL returns the URL that can be used without the router to get to web container.
func (app *DdevApp) GetWebContainerDirectHTTPURL() string {
// Get direct address of web container
Expand Down

0 comments on commit f9af3b6

Please sign in to comment.