Skip to content

Commit

Permalink
fix: use real path to global config location, fixes ddev#6328 (ddev#6329
Browse files Browse the repository at this point in the history
)
  • Loading branch information
stasadev authored Jun 24, 2024
1 parent 8b253a9 commit 94373f8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
11 changes: 6 additions & 5 deletions cmd/ddev/cmd/config-global.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

configTypes "github.com/ddev/ddev/pkg/config/types"
"github.com/ddev/ddev/pkg/fileutil"
"github.com/ddev/ddev/pkg/globalconfig"
globalconfigTypes "github.com/ddev/ddev/pkg/globalconfig/types"
"github.com/ddev/ddev/pkg/nodeps"
Expand Down Expand Up @@ -297,21 +298,21 @@ func init() {
configGlobalCommand.Flags().BoolVarP(&instrumentationOptIn, "instrumentation-opt-in", "", false, "instrumentation-opt-in=true")
configGlobalCommand.Flags().Bool("router-bind-all-interfaces", false, "router-bind-all-interfaces=true")
configGlobalCommand.Flags().Int("internet-detection-timeout-ms", 3000, "Increase timeout when checking internet timeout, in milliseconds")
configGlobalCommand.Flags().Bool("disable-http2", false, "Optionally disable http2 in deprecated nginx-proxy ddev-router, 'ddev global --disable-http2' or `ddev global --disable-http2=false'")
configGlobalCommand.Flags().Bool("use-letsencrypt", false, "Enables experimental Let's Encrypt integration, 'ddev global --use-letsencrypt' or `ddev global --use-letsencrypt=false'")
configGlobalCommand.Flags().String("letsencrypt-email", "", "Email associated with Let's Encrypt, `ddev global [email protected]'")
configGlobalCommand.Flags().Bool("disable-http2", false, "Optionally disable http2 in deprecated nginx-proxy ddev-router, 'ddev config global --disable-http2' or `ddev config global --disable-http2=false'")
configGlobalCommand.Flags().Bool("use-letsencrypt", false, "Enables experimental Let's Encrypt integration, 'ddev config global --use-letsencrypt' or `ddev config global --use-letsencrypt=false'")
configGlobalCommand.Flags().String("letsencrypt-email", "", "Email associated with Let's Encrypt, `ddev config global [email protected]'")
configGlobalCommand.Flags().Bool("simple-formatting", false, "If true, use simple formatting and no color for tables")
configGlobalCommand.Flags().Bool("use-hardened-images", false, "If true, use more secure 'hardened' images for an actual internet deployment.")
configGlobalCommand.Flags().Bool("fail-on-hook-fail", false, "If true, 'ddev start' will fail when a hook fails.")
configGlobalCommand.Flags().Bool("mutagen-enabled", false, "If true, web container will use Mutagen caching/asynchronous updates.")
_ = configGlobalCommand.Flags().MarkDeprecated("mutagen-enabled", fmt.Sprintf("please use --%s instead", configTypes.FlagPerformanceModeName))
configGlobalCommand.Flags().String(configTypes.FlagPerformanceModeName, configTypes.FlagPerformanceModeDefault, configTypes.FlagPerformanceModeDescription(configTypes.ConfigTypeGlobal))
configGlobalCommand.Flags().Bool(configTypes.FlagPerformanceModeResetName, true, configTypes.FlagPerformanceModeResetDescription(configTypes.ConfigTypeGlobal))
configGlobalCommand.Flags().String("table-style", "", "Table style for list and describe, see ~/.ddev/global_config.yaml for values")
configGlobalCommand.Flags().String("table-style", "", fmt.Sprintf("Table style for list and describe, see %s for values", fileutil.ShortHomeJoin(globalconfig.GetGlobalConfigPath())))
configGlobalCommand.Flags().String("required-docker-compose-version", "", "Override default docker-compose version (used only in development testing)")
_ = configGlobalCommand.Flags().MarkHidden("required-docker-compose-version")
configGlobalCommand.Flags().String("project-tld", "", "Override default project tld")
configGlobalCommand.Flags().Bool("use-docker-compose-from-path", true, "If true, use docker-compose from path instead of private ~/.ddev/bin/docker-compose (used only in development testing)")
configGlobalCommand.Flags().Bool("use-docker-compose-from-path", true, fmt.Sprintf("If true, use docker-compose from path instead of private %s (used only in development testing)", fileutil.ShortHomeJoin(globalconfig.GetDDEVBinDir(), "docker-compose")))
_ = configGlobalCommand.Flags().MarkHidden("use-docker-compose-from-path")
configGlobalCommand.Flags().Bool("no-bind-mounts", true, "If true, don't use bind-mounts - useful for environments like remote Docker where bind-mounts are impossible")
configGlobalCommand.Flags().String("xdebug-ide-location", "", "For less usual IDE locations specify where the IDE is running for Xdebug to reach it")
Expand Down
3 changes: 2 additions & 1 deletion pkg/ddevapp/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"time"

"github.com/ddev/ddev/pkg/fileutil"
"github.com/ddev/ddev/pkg/globalconfig"
"github.com/ddev/ddev/pkg/nodeps"
"github.com/ddev/ddev/pkg/output"
Expand Down Expand Up @@ -74,7 +75,7 @@ func List(settings ListCommandSettings) {
}
router := globalconfig.DdevGlobalConfig.Router
t.AppendFooter(table.Row{
"Router", routerStatus, "~/.ddev", globalconfig.GetRouterURL(), router},
"Router", routerStatus, fileutil.ShortHomeJoin(globalconfig.GetGlobalDdevDirLocation()), globalconfig.GetRouterURL(), router},
)
t.Render()
output.UserOut.WithField("raw", appDescs).Print(out.String())
Expand Down
14 changes: 14 additions & 0 deletions pkg/fileutil/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/ddev/ddev/pkg/nodeps"
"github.com/ddev/ddev/pkg/output"
"github.com/ddev/ddev/pkg/util"
"github.com/sirupsen/logrus"
)

// CopyFile copies the contents of the file named src to the file named
Expand Down Expand Up @@ -539,3 +540,16 @@ func ExpandFilesAndDirectories(dir string, paths []string) ([]string, error) {
}
return expanded, nil
}

// ShortHomeJoin returns the same result as filepath.Join() path with $HOME/ replaced by ~/
func ShortHomeJoin(elem ...string) string {
userHome, err := os.UserHomeDir()
if err != nil {
logrus.Fatalf("Could not get home directory for current user. Is it set? err=%v", err)
}
fullPath := filepath.Join(elem...)
if strings.HasPrefix(fullPath, userHome) {
return strings.Replace(fullPath, userHome, "~", 1)
}
return fullPath
}

0 comments on commit 94373f8

Please sign in to comment.