From 4cf470f2228197af9747e0b2b307dfae54d77746 Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Fri, 3 Jun 2022 16:17:53 +0200 Subject: [PATCH] Allow several compose file in -c arg --- cmd/katenary/utils.go | 18 +++++++++++++----- compose/parser.go | 20 +++++++++++--------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/cmd/katenary/utils.go b/cmd/katenary/utils.go index bc0d8b4..9e179e5 100644 --- a/cmd/katenary/utils.go +++ b/cmd/katenary/utils.go @@ -98,14 +98,22 @@ func Convert(composeFile, appVersion, appName, chartDir, chartVersion string, fo fmt.Println("No compose file given") return } - _, err := os.Stat(composeFile) - if err != nil { - fmt.Println("No compose file found") - os.Exit(1) + + composeFiles := strings.Split(composeFile, ",") + for i, c := range composeFiles { + composeFiles[i] = strings.TrimSpace(c) + } + + for _, composeFile := range composeFiles { + _, err := os.Stat(composeFile) + if err != nil { + fmt.Println("Error reading file:", composeFile) + os.Exit(1) + } } // Parse the compose file now - p := compose.NewParser(composeFile) + p := compose.NewParser(composeFiles) p.Parse(appName) dirname := filepath.Join(chartDir, appName) diff --git a/compose/parser.go b/compose/parser.go index 86b0cb5..2e8a1b0 100644 --- a/compose/parser.go +++ b/compose/parser.go @@ -26,32 +26,34 @@ var ( ) // NewParser create a Parser and parse the file given in filename. If filename is empty, we try to parse the content[0] argument that should be a valid YAML content. -func NewParser(filename string, content ...string) *Parser { +func NewParser(filename []string, content ...string) *Parser { p := &Parser{} if len(content) > 0 { // mainly for the tests... - dir := filepath.Dir(filename) + dir := filepath.Dir(filename[0]) err := os.MkdirAll(dir, 0755) if err != nil { log.Fatal(err) } p.temporary = &dir - ioutil.WriteFile(filename, []byte(content[0]), 0644) - cli.DefaultFileNames = []string{filename} + ioutil.WriteFile(filename[0], []byte(content[0]), 0644) + cli.DefaultFileNames = filename } // if filename is not in cli Default files, add it if len(filename) > 0 { found := false - for _, f := range cli.DefaultFileNames { - if f == filename { - found = true - break + for _, defaultFileName := range cli.DefaultFileNames { + for _, givenFileName := range filename { + if defaultFileName == givenFileName { + found = true + break + } } } // add the file at first position if !found { - cli.DefaultFileNames = append([]string{filename}, cli.DefaultFileNames...) + cli.DefaultFileNames = append(filename, cli.DefaultFileNames...) } }