@@ -30,22 +30,33 @@ func isDirectory(path string) (bool, error) {
3030}
3131
3232func getComposeFilesInDir (basePath string ) ([]string , error ) {
33+ maxDepth := 3
3334 isDir , err := isDirectory (basePath )
3435 if err != nil {
3536 return nil , err
3637 }
3738 if ! isDir {
38- return nil , fmt .Errorf ("%s is not a Directory " , basePath )
39+ return nil , fmt .Errorf ("%s is not a directory " , basePath )
3940 }
4041
4142 composeFileNames := []string {"docker-compose.yml" , "docker-compose.yaml" , "compose.yml" , "compose.yaml" }
4243 var composeFiles []string
43-
44+
4445 err = filepath .Walk (basePath , func (path string , info os.FileInfo , err error ) error {
4546 if err != nil {
4647 return err
4748 }
4849
50+ relativePath , err := filepath .Rel (basePath , path )
51+
52+ if err != nil {
53+ return err
54+ }
55+ depth := strings .Count (relativePath , string (os .PathSeparator ))
56+ if depth >= maxDepth {
57+ return filepath .SkipDir
58+ }
59+
4960 if ! info .IsDir () {
5061 for _ , fileName := range composeFileNames {
5162 if filepath .Base (path ) == fileName {
@@ -62,7 +73,7 @@ func getComposeFilesInDir(basePath string) ([]string, error) {
6273 }
6374
6475 if len (composeFiles ) == 0 {
65- return nil , fmt .Errorf ("no Docker Compose files found in %s" , basePath )
76+ return nil , fmt .Errorf ("no docker compose files found in %s" , basePath )
6677 }
6778
6879 return composeFiles , nil
@@ -177,7 +188,7 @@ func main() {
177188 os .Exit (1 )
178189 }
179190 if len (allComposeFiles ) == 0 {
180- fmt .Printf ("Error: no docker Docker Compose YAML found in %s\n " , paths )
191+ fmt .Printf ("Error: no docker compose YAML found in %s\n " , paths )
181192 os .Exit (1 )
182193 }
183194
0 commit comments