detect if a file or directory was passed. if a directory, gather all files in it the order is file lookup, json lookup then yaml
(ctx context.Context, fpath string)
| 73 | // detect if a file or directory was passed. if a directory, gather all files in it |
| 74 | // the order is file lookup, json lookup then yaml |
| 75 | func detectInput(ctx context.Context, fpath string) ([]string, error) { |
| 76 | if utils.IsJson(fpath) { |
| 77 | log.Debug("valid JSON found for definition file") |
| 78 | return inputFromString(ctx, fpath) |
| 79 | } |
| 80 | log.Debug("unable to detect input as JSON") |
| 81 | |
| 82 | // this is narrowed down to map[string]interface{} |
| 83 | // since a provided filename that does not exist could be considered valid yaml |
| 84 | if utils.IsYamlMap(fpath) { |
| 85 | log.Debug("valid YAML map found for definition file") |
| 86 | return inputFromString(ctx, fpath) |
| 87 | } |
| 88 | log.Debug("unable to detect input as YAML") |
| 89 | |
| 90 | fileExists, err := utils.IsFile(ctx, fpath) |
| 91 | if err != nil { |
| 92 | return nil, err |
| 93 | } |
| 94 | |
| 95 | if fileExists { |
| 96 | return fileLookup(ctx, fpath) |
| 97 | } |
| 98 | log.Debugf("unable to detect a file at path %v", fpath) |
| 99 | |
| 100 | return nil, fmt.Errorf("unable to parse the provided input file: %v", fpath) |
| 101 | } |
| 102 | |
| 103 | // if a single file is provided, return it |
| 104 | // if the file is a directory, return the files inside the directory |
no test coverage detected