Skip to content

Commit

Permalink
Fix relative dir calculation with multiple configs
Browse files Browse the repository at this point in the history
Resolves #25
  • Loading branch information
svrana committed Jun 14, 2019
1 parent 68d0421 commit 3f97659
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 7 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ type Project struct {
// The paths of the docker compose files for this project. Can be
// relative or absolute paths.
DockerComposeFilenames []string `mapstructure:"docker_compose_files"`
// The path of the root of the project (or its basename). Do we need this?
// Directory is the full-path to the location of the dev configuration
// file that contains this project configuration.
Directory string `mapstructure:"directory"`
// Ignored if set by user.
Name string `mapstructure:"name"`
Expand Down Expand Up @@ -202,6 +203,11 @@ func setDefaults(config *Dev) {
if project.Name == "" {
project.Name = name
}
// Have to remember where the project was defined so we can
// figure out relative directories when launching commands. See
// Project.Shell. This is also passed in when parsing docker-compose
// files where it used to load env files.
project.Directory = filepath.Dir(config.Filename)
}
}

Expand Down
3 changes: 1 addition & 2 deletions project.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package dev
import (
"fmt"
"os"
"path/filepath"
"strings"

log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -78,9 +77,9 @@ func (p *Project) Shell(appConfig *c.Dev, args []string) {
if err != nil {
log.Fatalf("Failed to get current directory: %s", err)
}
configDir := filepath.Dir(appConfig.Filename)

relativePath := ""
configDir := p.Config.Directory
if strings.HasPrefix(cwd, configDir) {
start := strings.Index(cwd, configDir) + len(configDir) + 1
if start < len(cwd) {
Expand Down

0 comments on commit 3f97659

Please sign in to comment.