From 4be18682677a35b8a0cc9c21f753c65c6ea5c8e5 Mon Sep 17 00:00:00 2001 From: SteveRuble Date: Thu, 16 May 2019 12:49:49 -0400 Subject: [PATCH] fix(workspace): support relative path imports The workspace was ignoring relative paths in the import list; this fix makes them work again. --- cmd/workspace.go | 34 +++++++--------------------------- pkg/bosun/workspace.go | 2 ++ 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/cmd/workspace.go b/cmd/workspace.go index 4ea52da..4f1ebd5 100644 --- a/cmd/workspace.go +++ b/cmd/workspace.go @@ -17,6 +17,7 @@ package cmd import ( "encoding/json" "fmt" + "github.com/naveego/bosun/pkg/util" "github.com/oliveagle/jsonpath" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -24,7 +25,6 @@ import ( "gopkg.in/yaml.v2" "os" "path/filepath" - "strings" ) func init() { @@ -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 diff --git a/pkg/bosun/workspace.go b/pkg/bosun/workspace.go index 29fea59..bc750c9 100644 --- a/pkg/bosun/workspace.go +++ b/pkg/bosun/workspace.go @@ -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