MCPcopy Create free account
hub / github.com/conforma/cli / fileLookup

Function fileLookup

internal/input/validate.go:105–139  ·  view source on GitHub ↗

if a single file is provided, return it if the file is a directory, return the files inside the directory

(ctx context.Context, path string)

Source from the content-addressed store, hash-verified

103// if a single file is provided, return it
104// if the file is a directory, return the files inside the directory
105func fileLookup(ctx context.Context, path string) ([]string, error) {
106 fs := utils.FS(ctx)
107 var defFiles []string
108
109 file, err := fs.Open(path)
110 if err != nil {
111 return nil, err
112 }
113
114 defer file.Close()
115
116 dir, err := afero.IsDir(fs, path)
117 if err != nil {
118 return nil, err
119 }
120
121 if dir {
122 files, err := afero.ReadDir(fs, path)
123 if err != nil {
124 return nil, err
125 }
126 // a directory was provided, but contained no files
127 if len(files) == 0 {
128 return nil, fmt.Errorf("the directory %v contained no files", path)
129 }
130
131 for _, f := range files {
132 defFiles = append(defFiles, filepath.Join(path, f.Name()))
133 }
134 } else {
135 defFiles = append(defFiles, path)
136 }
137
138 return defFiles, nil
139}
140
141// write the input file if a json or yaml string is provided
142func inputFromString(ctx context.Context, data string) ([]string, error) {

Callers 1

detectInputFunction · 0.85

Calls 5

FSFunction · 0.92
CloseMethod · 0.65
ErrorfMethod · 0.65
NameMethod · 0.65
OpenMethod · 0.45

Tested by

no test coverage detected