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)
| 103 | // if a single file is provided, return it |
| 104 | // if the file is a directory, return the files inside the directory |
| 105 | func 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 |
| 142 | func inputFromString(ctx context.Context, data string) ([]string, error) { |