From c5568a2fc59637e8c9ddc69d6554519d32f105da Mon Sep 17 00:00:00 2001 From: Andrii Klymiuk Date: Mon, 31 Oct 2022 10:45:55 +0200 Subject: [PATCH] Fix default corgi compose file path --- utils/config.go | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/utils/config.go b/utils/config.go index 01df5f7..e29ee2d 100644 --- a/utils/config.go +++ b/utils/config.go @@ -80,12 +80,11 @@ func GetCorgiServices(cobra *cobra.Command) (*CorgiCompose, error) { pathToCorgiComposeFile = filenameFlag } if pathToCorgiComposeFile == "" { - chosenCorgiPath, err := getCorgiConfigFromAlert() - if err != nil || chosenCorgiPath == "" { - pathToCorgiComposeFile = "corgi-compose.yml" - } else { - pathToCorgiComposeFile = chosenCorgiPath + chosenPathToCorgiCompose, err := getCorgiConfigFilePath() + if err != nil { + return nil, err } + pathToCorgiComposeFile = chosenPathToCorgiCompose } describeFlag, err := cobra.Root().Flags().GetBool("describe") @@ -268,6 +267,29 @@ func IsServiceIncludedInFlag(services []string, serviceName string) bool { return isIncluded } +func getCorgiConfigFilePath() (string, error) { + defaultCorgiConfigName := "corgi-compose.yml" + corgiComposeExists, err := CheckIfFileExistsInDirectory( + ".", + defaultCorgiConfigName, + ) + if err != nil { + return "", err + } + if corgiComposeExists { + return defaultCorgiConfigName, nil + } + + chosenCorgiPath, err := getCorgiConfigFromAlert() + if err != nil { + return "", err + } + if err != nil || chosenCorgiPath == "" { + return "", err + } + return chosenCorgiPath, nil +} + func getCorgiConfigFromAlert() (string, error) { var files []string err := filepath.WalkDir(".", func(path string, directory fs.DirEntry, err error) error {