Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create new HeidiSQL command for Windows and WSL2 #2679

Merged
merged 8 commits into from Dec 29, 2020
25 changes: 19 additions & 6 deletions cmd/ddev/cmd/commands.go
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"bufio"
"fmt"
"github.com/drud/ddev/pkg/nodeps"
"io/ioutil"
"os"
"path"
Expand Down Expand Up @@ -140,9 +141,11 @@ func addCustomCommands(rootCmd *cobra.Command) error {
osTypes = val
}

// If OSTypes is specified and we aren't this isn't a specified OS, skip
if osTypes != "" && !strings.Contains(osTypes, runtime.GOOS) {
continue
// If OSTypes is specified and we aren't on one of the specified OSes, skip
if osTypes != "" {
if !strings.Contains(osTypes, runtime.GOOS) && !(strings.Contains(osTypes, "wsl2") && nodeps.IsWSL2()) {
continue
}
}

// Import and handle HostBinaryExists
Expand All @@ -151,8 +154,18 @@ func addCustomCommands(rootCmd *cobra.Command) error {
}

// If hostBinaryExists is specified it doesn't exist here, skip
if hostBinaryExists != "" && !fileutil.FileExists(hostBinaryExists) {
continue
if hostBinaryExists != "" {
binExists := false
bins := strings.Split(hostBinaryExists, ",")
for _, bin := range bins {
if fileutil.FileExists(bin) {
binExists = true
break
}
}
if !binExists {
continue
}
}

// Create proper description suffix
Expand Down Expand Up @@ -284,7 +297,7 @@ func findDirectivesInScriptCommand(script string) map[string]string {
if strings.HasPrefix(line, "## ") && strings.Contains(line, ":") {
line = strings.Replace(line, "## ", "", 1)
parts := strings.SplitN(line, ":", 2)
parts[1] = strings.Trim(parts[1], " ")
parts[1] = strings.Trim(parts[1], " \"'")
directives[parts[0]] = parts[1]
}
}
Expand Down
21 changes: 21 additions & 0 deletions cmd/ddev/cmd/global_dotddev_assets/commands/host/heidisql
@@ -0,0 +1,21 @@
#!/bin/bash

## #ddev-generated: If you want to edit and own this file, remove this line.
## Description: Run HeidiSQL against current db
## Usage: heidisql
## Example: "ddev heidisql"
## OSTypes: windows,wsl2
## HostBinaryExists: "/mnt/c/Program Files/HeidiSQL/heidisql.exe,C:\Program Files\HeidiSQL\Heidisql.exe"

arguments="--host=127.0.0.1 --port=${DDEV_HOST_DB_PORT} --user=root --password=root --description=${DDEV_SITENAME}"

case $OSTYPE in
"win*"* | "msys"*)
'/c/Program Files/HeidiSQL/heidisql.exe' "$arguments" &
;;
# linux-gnu in this case is only WSL2 as selected in OSTypes above
"linux-gnu")
# HeidiSQL is Microsoft only, but we want to start it from WSL2
"/mnt/c/Program Files/HeidiSQL/heidisql.exe" "$arguments" &
;;
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.

3 changes: 2 additions & 1 deletion docs/users/cli-usage.md
Expand Up @@ -11,7 +11,8 @@ Each of these commands has full help. For example, `ddev start -h` or `ddev help
* `ddev describe` or `ddev describe <projectname>` gives you full details about the project, what ports it uses, how to access them, etc.
* `ddev list` shows running projects
* `ddev mysql` gives direct access to the mysql client
* `ddev sequelpro` or `ddev sequelace` (macOS only, if installed) give access to the Sequel Pro or Sequel Ace database browser GUIs (if installed)
* `ddev sequelpro`, `ddev sequelace`, and `ddev tableplus` (macOS only, if the app is installed) give access to the Sequel Pro, Sequel Ace, or TablePlus database browser GUIs.
* `ddev heidisql` (Windows/WSL2 only, if installed) gives access to the HeidiSQL database browser GUI.
* `ddev import-db` and `ddev export-db` let you import or export a sql or compressed sql file.
* `ddev composer` lets you run composer (inside the container), for example `ddev composer install` will do a full composer install for you without even needing composer on your computer. See [developer tools](developer-tools.md#ddev-and-composer).
* `ddev snapshot` makes a very fast snapshot of your database that can be easily and quickly restored with `ddev restore-snapshot`.
Expand Down
2 changes: 1 addition & 1 deletion pkg/ddevapp/instrumentation.go
Expand Up @@ -29,7 +29,7 @@ func (n *SegmentNoopLogger) Errorf(format string, args ...interface{}) {}

// ReportableEvents is the list of events that we choose to report specifically.
// Excludes non-ddev custom commands.
var ReportableEvents = map[string]bool{"auth": true, "composer": true, "config": true, "debug": true, "delete": true, "describe": true, "exec": true, "export-db": true, "import-db": true, "import-files": true, "launch": true, "list": true, "logs": true, "mysql": true, "pause": true, "poweroff": true, "pull": true, "restart": true, "restore-snapshot": true, "sequelace": true, "sequelpro": true, "share": true, "snapshot": true, "ssh": true, "start": true, "stop": true, "tableplus": true, "xdebug": true}
var ReportableEvents = map[string]bool{"auth": true, "composer": true, "config": true, "debug": true, "delete": true, "describe": true, "exec": true, "export-db": true, "heidisql": true, "import-db": true, "import-files": true, "launch": true, "list": true, "logs": true, "mysql": true, "pause": true, "poweroff": true, "pull": true, "restart": true, "restore-snapshot": true, "sequelace": true, "sequelpro": true, "share": true, "snapshot": true, "ssh": true, "start": true, "stop": true, "tableplus": true, "xdebug": true}

// GetInstrumentationUser normally gets just the hashed hostID but if
// an explicit user is provided in global_config.yaml that will be prepended.
Expand Down
3 changes: 1 addition & 2 deletions pkg/globalconfig/global_config.go
Expand Up @@ -12,7 +12,6 @@ import (
"net"
"os"
"os/exec"
"path"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -218,7 +217,7 @@ func GetGlobalDdevDir() string {
if err != nil {
logrus.Fatal("could not get home directory for current user. is it set?")
}
ddevDir := path.Join(userHome, ".ddev")
ddevDir := filepath.Join(userHome, ".ddev")

// Create the directory if it is not already present.
if _, err := os.Stat(ddevDir); os.IsNotExist(err) {
Expand Down
5 changes: 5 additions & 0 deletions pkg/nodeps/utils.go
Expand Up @@ -53,6 +53,11 @@ func RandomString(length int) string {
return string(b)
}

// IsWSL2() returns true if running WSL2
func IsWSL2() bool {
return GetWSLDistro() != ""
}

// GetWSLDistro returns the WSL2 distro name if on Linux
func GetWSLDistro() string {
wslDistro := ""
Expand Down