diff --git a/bosun.yaml b/bosun.yaml index c216881..c077b2d 100644 --- a/bosun.yaml +++ b/bosun.yaml @@ -6,7 +6,7 @@ appRefs: {} apps: - name: bosun repo: naveego/bosun - version: 0.8.3 + version: 0.8.4 images: [] scripts: - name: publish diff --git a/cmd/env.go b/cmd/env.go index a376725..b8251fa 100644 --- a/cmd/env.go +++ b/cmd/env.go @@ -15,10 +15,12 @@ package cmd import ( + "errors" "fmt" "github.com/naveego/bosun/pkg" "github.com/naveego/bosun/pkg/bosun" "github.com/spf13/cobra" + "github.com/spf13/viper" "io/ioutil" "os" "path/filepath" @@ -88,15 +90,21 @@ var envCmd = addCommand(rootCmd, &cobra.Command{ cmd.Flags().Bool(ArgEnvCurrent, false, "Write script for setting current environment.") }) -var envNameCmd = &cobra.Command{ +var envNameCmd = addCommand(envCmd, &cobra.Command{ Use: "name", Short: "Prints the name of the current environment.", - Run: func(cmd *cobra.Command, args []string) { - b := mustGetBosun() - e := b.GetCurrentEnvironment() - fmt.Println(e.Name) + RunE: func(cmd *cobra.Command, args []string) error { + config, err := bosun.LoadWorkspaceNoImports(viper.GetString(ArgBosunConfigFile)) + if err != nil { + return err + } + if config.CurrentEnvironment == "" { + return errors.New("no current environment set") + } + fmt.Println(config.CurrentEnvironment) + return nil }, -} +}) var envListCmd = addCommand(envCmd, &cobra.Command{ Use: "list", diff --git a/pkg/bosun/workspace.go b/pkg/bosun/workspace.go index 6ee7bda..9af1781 100644 --- a/pkg/bosun/workspace.go +++ b/pkg/bosun/workspace.go @@ -54,7 +54,7 @@ type State struct { Microservices map[string]AppState } -func LoadWorkspace(path string) (*Workspace, error) { +func LoadWorkspaceNoImports(path string) (*Workspace, error) { defaultPath := os.ExpandEnv("$HOME/.bosun/bosun.yaml") if path == "" { path = defaultPath @@ -91,6 +91,17 @@ func LoadWorkspace(path string) (*Workspace, error) { return nil, errors.Wrap(err, "loading root config") } + return c, nil + +} + +func LoadWorkspace(path string) (*Workspace, error) { + + c, err := LoadWorkspaceNoImports(path) + if err != nil { + return nil, err + } + err = c.importFromPaths(path, c.Imports) if err != nil {