@@ -61,31 +61,30 @@ func expandGlob(patterns []string) ([]string, error) {
6161 }
6262
6363 if len (matches ) == 0 {
64- // Check if it's a literal file path that exists
65- if _ , err := os .Stat (pattern ); err == nil {
66- if ! seen [pattern ] {
67- seen [pattern ] = true
68- files = append (files , pattern )
69- }
70- } else {
71- return nil , fmt .Errorf ("no files matched pattern: %s" , pattern )
72- }
73- continue
64+ return nil , fmt .Errorf ("no files matched pattern: %s" , pattern )
7465 }
7566
67+ added := 0
7668 for _ , match := range matches {
69+ info , err := os .Stat (match )
70+ if err != nil || info .IsDir () {
71+ continue
72+ }
7773 if ! seen [match ] {
7874 seen [match ] = true
7975 files = append (files , match )
76+ added ++
8077 }
8178 }
79+ if added == 0 {
80+ return nil , fmt .Errorf ("no files matched pattern: %s" , pattern )
81+ }
8282 }
8383
8484 return files , nil
8585}
8686
8787func runApply (ctx context.Context , filePatterns []string ) error {
88- // Expand glob patterns to file paths
8988 files , err := expandGlob (filePatterns )
9089 if err != nil {
9190 return err
@@ -95,7 +94,6 @@ func runApply(ctx context.Context, filePatterns []string) error {
9594 return fmt .Errorf ("no files to apply" )
9695 }
9796
98- // Create API client
9997 apiURL := viper .GetString ("url" )
10098 apiKey := viper .GetString ("api-key" )
10199 workspace := viper .GetString ("workspace" )
@@ -107,7 +105,6 @@ func runApply(ctx context.Context, filePatterns []string) error {
107105
108106 workspaceID := client .GetWorkspaceID (ctx , workspace )
109107
110- // Parse all files and collect documents
111108 var documents []Document
112109 for _ , filePath := range files {
113110 docs , err := ParseFile (filePath )
@@ -124,30 +121,42 @@ func runApply(ctx context.Context, filePatterns []string) error {
124121
125122 log .Info ("Applying resources" , "count" , len (documents ), "files" , len (files ))
126123
127- // Create document context
128124 docCtx := NewDocContext (workspaceID .String (), client )
129125 docCtx .Context = ctx
130126
131- // Sort documents by Order (lower number = processed first)
132- // Sort documents by Order (higher number = higher priority = processed first)
133- sort .Slice (documents , func (i , j int ) bool {
134- return documents [i ].Order () > documents [j ].Order ()
127+ var resourceDocs []* ResourceDocument
128+ var otherDocs []Document
129+ for _ , doc := range documents {
130+ if rd , ok := doc .(* ResourceDocument ); ok {
131+ resourceDocs = append (resourceDocs , rd )
132+ } else {
133+ otherDocs = append (otherDocs , doc )
134+ }
135+ }
136+
137+ sort .Slice (otherDocs , func (i , j int ) bool {
138+ return otherDocs [i ].Order () > otherDocs [j ].Order ()
135139 })
136140
137- // Apply all documents
138141 var results []ApplyResult
139- for _ , doc := range documents {
142+ for _ , doc := range otherDocs {
140143 result , err := doc .Apply (docCtx )
141144 if err != nil {
142145 log .Error ("Failed to apply document" , "error" , err )
143146 }
144147 results = append (results , result )
145148 }
146149
147- // Print summary
150+ if len (resourceDocs ) > 0 {
151+ resourceResults , err := applyResourcesBatch (docCtx , resourceDocs )
152+ if err != nil {
153+ log .Error ("Failed to apply resources batch" , "error" , err )
154+ }
155+ results = append (results , resourceResults ... )
156+ }
157+
148158 printResults (results )
149159
150- // Check for errors
151160 for _ , r := range results {
152161 if r .Error != nil {
153162 return fmt .Errorf ("one or more resources failed to apply" )
0 commit comments