Skip to content

Commit

Permalink
Show all corgi-compose files, if not chosen before
Browse files Browse the repository at this point in the history
  • Loading branch information
Andriiklymiuk committed Oct 24, 2022
1 parent e669cee commit 5a7dbeb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ corgi init
corgi run
`,
Version: "1.1.29",
Version: "1.1.30",
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand Down
52 changes: 51 additions & 1 deletion utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"strconv"
"strings"

Expand Down Expand Up @@ -73,10 +74,19 @@ func GetCorgiServices(cobra *cobra.Command) (*CorgiCompose, error) {
if err != nil {
return nil, err
}
pathToCorgiComposeFile := "corgi-compose.yml"
var pathToCorgiComposeFile string
if filenameFlag != "" {
pathToCorgiComposeFile = filenameFlag
}
if pathToCorgiComposeFile == "" {
chosenCorgiPath, err := getCorgiConfigFromAlert()
if err != nil || chosenCorgiPath == "" {
pathToCorgiComposeFile = "corgi-compose.yml"
} else {
pathToCorgiComposeFile = chosenCorgiPath
}
}

describeFlag, err := cobra.Root().Flags().GetBool("describe")
if err != nil {
return nil, err
Expand Down Expand Up @@ -256,3 +266,43 @@ func IsServiceIncludedInFlag(services []string, serviceName string) bool {
}
return isIncluded
}

func getCorgiConfigFromAlert() (string, error) {
var files []string
err := filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
if err != nil {
fmt.Println(err)
return nil
}
if info.IsDir() {
return nil
}
if filepath.Ext(path) != ".yml" && filepath.Ext(path) != ".yaml" {
return nil
}
if !strings.Contains(info.Name(), "corgi") {
return nil
}

files = append(files, path)

return nil
})

if err != nil {
fmt.Println(err)
return "", err
}

file, err := PickItemFromListPrompt(
"Select corgi config file to use",
files,
"none",
)
if err != nil {
fmt.Println(err)
return "", err
}

return file, nil
}

0 comments on commit 5a7dbeb

Please sign in to comment.