Skip to content

Commit

Permalink
fix(workspace): support relative path imports
Browse files Browse the repository at this point in the history
The workspace was ignoring relative paths in the import list; this fix makes them work again.
  • Loading branch information
SteveRuble committed May 16, 2019
1 parent 2c95121 commit 4be1868
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
34 changes: 7 additions & 27 deletions cmd/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ package cmd
import (
"encoding/json"
"fmt"
"github.com/naveego/bosun/pkg/util"
"github.com/oliveagle/jsonpath"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"gopkg.in/yaml.v2"
"os"
"path/filepath"
"strings"
)

func init() {
Expand Down Expand Up @@ -62,35 +62,15 @@ var configShowImportsCmd = addCommand(configShowCmd, &cobra.Command{
c := b.GetWorkspace()
visited := map[string]bool{}

var visit func(path string, depth int, last bool)
visit = func(path string, depth int, last bool) {
if file, ok := c.ImportedBosunFiles[path]; ok {
symbol := "├─"
if last {
symbol = "└─"
}
fmt.Printf("%s%s%s\n", strings.Repeat(" ", depth), symbol, path)

if visited[path] {
return
}

visited[path] = true

for i, importPath := range file.Imports {
if !filepath.IsAbs(importPath) {
importPath = filepath.Join(filepath.Dir(path), importPath)
}
visit(importPath, depth+1, i+1 >= len(file.Imports))
}
} else {

}
for path := range c.ImportedBosunFiles {
visited[path] = true
}

paths := util.SortedKeys(visited)

fmt.Println(c.Path)
for i, path := range c.Imports {
visit(path, 0, i+1 == len(c.Imports))
for _, path := range paths {
fmt.Println(path)
}

return nil
Expand Down
2 changes: 2 additions & 0 deletions pkg/bosun/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ func LoadWorkspaceNoImports(path string) (*Workspace, error) {

func LoadWorkspace(path string) (*Workspace, error) {

path, _ = filepath.Abs(os.ExpandEnv(path))

c, err := LoadWorkspaceNoImports(path)
if err != nil {
return nil, err
Expand Down

0 comments on commit 4be1868

Please sign in to comment.