MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / CollectYAMLFiles

Function CollectYAMLFiles

app/cli/pkg/action/apply.go:132–161  ·  view source on GitHub ↗

CollectYAMLFiles returns YAML file paths from the given path. If path is a file, it returns that file. If a directory, it walks recursively.

(path string)

Source from the content-addressed store, hash-verified

130// CollectYAMLFiles returns YAML file paths from the given path.
131// If path is a file, it returns that file. If a directory, it walks recursively.
132func CollectYAMLFiles(path string) ([]string, error) {
133 info, err := os.Stat(path)
134 if err != nil {
135 return nil, fmt.Errorf("accessing path %q: %w", path, err)
136 }
137
138 if !info.IsDir() {
139 return []string{path}, nil
140 }
141
142 var files []string
143 err = filepath.WalkDir(path, func(p string, d os.DirEntry, err error) error {
144 if err != nil {
145 return err
146 }
147 if d.IsDir() {
148 return nil
149 }
150 ext := strings.ToLower(filepath.Ext(p))
151 if ext == ".yaml" || ext == ".yml" {
152 files = append(files, p)
153 }
154 return nil
155 })
156 if err != nil {
157 return nil, fmt.Errorf("walking directory %q: %w", path, err)
158 }
159
160 return files, nil
161}
162
163// SplitYAMLDocuments splits a potentially multi-document YAML file into individual documents,
164// extracting kind and name from each.

Callers 1

ParseYAMLPathFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected