feat: support passing mutiple files in a single flag

This commit is contained in:
rick 2023-01-10 15:20:12 +08:00
parent 84afe70659
commit 5419a5ead4
3 changed files with 25 additions and 1 deletions

View file

@ -165,6 +165,11 @@ $ echo $?
1
```
* Validating mutiple files with a single flag
```bash
kubeconform fixtures/valid.yaml,fixtures/valid_version.yaml
```
* Passing manifests via Stdin
```bash
cat fixtures/valid.yaml | ./bin/kubeconform -summary

View file

@ -91,7 +91,14 @@ func FromFlags(progName string, args []string) (Config, string, error) {
c.RejectKinds = splitCSV(rejectKindsCSV)
c.IgnoreFilenamePatterns = ignoreFilenamePatterns
c.SchemaLocations = schemaLocationsParam
c.Files = flags.Args()
files := flags.Args()
for _, file := range files {
if strings.Contains(file, ",") {
c.Files = append(c.Files, strings.Split(file, ",")...)
} else {
c.Files = append(c.Files, file)
}
}
if c.Help {
flags.Usage()

View file

@ -129,6 +129,18 @@ func TestFromFlags(t *testing.T) {
Verbose: true,
},
},
{
[]string{"file1,file2,file3"},
Config{
Files: []string{"file1", "file2", "file3"},
KubernetesVersion: "master",
NumberOfWorkers: 4,
OutputFormat: "text",
SchemaLocations: nil,
SkipKinds: map[string]struct{}{},
RejectKinds: map[string]struct{}{},
},
},
}
for i, testCase := range testCases {