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

Function detectInput

internal/input/validate.go:75–101  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
75func 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

Callers 1

ValidateInputFunction · 0.85

Calls 6

IsJsonFunction · 0.92
IsYamlMapFunction · 0.92
IsFileFunction · 0.92
inputFromStringFunction · 0.85
fileLookupFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected