Skip to content

Commit

Permalink
Update main.go to call the cobra file
Browse files Browse the repository at this point in the history
  • Loading branch information
Checksumz committed Jul 17, 2024
1 parent f9c7cee commit 5f9ea91
Showing 1 changed file with 17 additions and 43 deletions.
60 changes: 17 additions & 43 deletions cmd/yaml-lint/main.go
Original file line number Diff line number Diff line change
@@ -1,51 +1,25 @@
package main
/*
Copyright 2020 The Kubernetes Authors.
import (
"fmt"
"os"
"strings"
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
"sigs.k8s.io/yaml"
)
http://www.apache.org/licenses/LICENSE-2.0
// validateYAML reads and parses the YAML file at the given path.
func validateYAML(filePath string) string {
data, err := os.ReadFile(filePath)
if err != nil {
return fmt.Sprintf("Error reading %s:\n%s", filePath, err.Error())
}
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

var content interface{}
if err := yaml.UnmarshalStrict(data, &content); err != nil {
return fmt.Sprintf("Error in %s:\n%w", filePath, err.Error())
}
package main

return "Valid"
}
import (
"k8s.io/release/cmd/publish-release/cmd"
)

func main() {
if len(os.Args) < 2 {
fmt.Println("No YAML files specified.")
os.Exit(1)
}

files := os.Args[1:]
invalidFiles := []string{}

for _, file := range files {
result := validateYAML(file)
if result != "Valid" {
invalidFiles = append(invalidFiles, result)
}
}

if len(invalidFiles) > 0 {
fmt.Println("YAML Validation Failed:\n")
for _, errorMsg := range invalidFiles {
fmt.Println(errorMsg)
fmt.Println("\n" + strings.Repeat("-", 40) + "\n")
}
} else {
fmt.Println("All YAML files are valid 🎉.")
}
cmd.Execute()
}

0 comments on commit 5f9ea91

Please sign in to comment.