diff --git a/compose/compose.go b/compose/compose.go index 77253ae2d..8c9e47b9f 100644 --- a/compose/compose.go +++ b/compose/compose.go @@ -1,6 +1,7 @@ package compose import ( + "errors" "path/filepath" "strings" @@ -19,13 +20,19 @@ type ComposeProject struct { } func Load(name string, configpaths []string) (*ComposeProject, error) { - if name == "" { - name = "docker-compose" - } model, workingDir, err := internal.GetConfig(name, configpaths) if err != nil { return nil, err } + + if name == "" { + if model != nil { + name = filepath.Base(filepath.Dir(model.Filename)) + } else if workingDir != "" { + name = filepath.Base(filepath.Dir(workingDir)) + } + } + return &ComposeProject{ config: model, helm: helm.NewHelmActions(nil), @@ -35,6 +42,10 @@ func Load(name string, configpaths []string) (*ComposeProject, error) { } func (cp *ComposeProject) GenerateChart(dirname string) error { + if cp.config == nil { + return errors.New(`Can't find a suitable configuration file in this directory or any +parent. Are you in the right directory?`) + } if dirname == "" { dirname = cp.config.Filename if strings.Contains(dirname, ".") { @@ -51,7 +62,13 @@ func (cp *ComposeProject) Install(name, path string) error { if path != "" { return cp.helm.InstallChartFromDir(name, path) } - + if cp.config == nil { + return errors.New(`Can't find a suitable configuration file in this directory or any +parent. Are you in the right directory?`) + } + if name == "" { + name = cp.Name + } chart, err := internal.GetChartInMemory(cp.config, name) if err != nil { return err @@ -60,6 +77,16 @@ func (cp *ComposeProject) Install(name, path string) error { } func (cp *ComposeProject) Uninstall(name string) error { + if name == "" { + if cp.config == nil { + return errors.New(`Can't find a suitable configuration file in this directory or any +parent. Are you in the right directory? + +Alternative: uninstall [INSTALLATION NAME] +`) + } + name = cp.Name + } return cp.helm.Uninstall(name) } diff --git a/compose/internal/env.go b/compose/internal/env.go index 72075138b..141f15b1e 100644 --- a/compose/internal/env.go +++ b/compose/internal/env.go @@ -29,9 +29,6 @@ func Environment() map[string]string { } func GetConfig(name string, configPaths []string) (*types.Config, string, error) { - if name == "" { - name = "docker-compose" - } workingDir, configs, err := utils.GetConfigs( name, configPaths, @@ -39,6 +36,9 @@ func GetConfig(name string, configPaths []string) (*types.Config, string, error) if err != nil { return nil, "", err } + if configs == nil { + return nil, "", nil + } config, err := loader.Load(types.ConfigDetails{ WorkingDir: workingDir, ConfigFiles: configs, diff --git a/compose/internal/utils/config.go b/compose/internal/utils/config.go index 93baa91da..9db651b43 100644 --- a/compose/internal/utils/config.go +++ b/compose/internal/utils/config.go @@ -1,7 +1,6 @@ package utils import ( - "fmt" "io/ioutil" "os" "path/filepath" @@ -20,6 +19,9 @@ func GetConfigs(name string, configPaths []string) (string, []types.ConfigFile, if err != nil { return "", nil, err } + if configPath == nil { + return "", nil, nil + } workingDir := filepath.Dir(configPath[0]) if name == "" { @@ -88,7 +90,7 @@ func getConfigPaths(configPaths []string) ([]string, error) { } parent := filepath.Dir(pwd) if parent == pwd { - return nil, fmt.Errorf("Can't find a suitable configuration file in this directory or any parent. Are you in the right directory?") + return nil, nil } pwd = parent }