Metadata tool correction: Output empty proto in case of no input

Change-Id: I85ca22574433ab164c303c1f6b0d29191e704cbb
This commit is contained in:
Aditya Choudhary 2024-01-11 11:12:44 +00:00
parent f28fa571d0
commit f0670e89f4
2 changed files with 19 additions and 11 deletions

View file

@ -77,9 +77,18 @@ func readFileToString(filePath string) string {
return string(data)
}
func writeNewlineToOutputFile(outputFile string) {
func writeEmptyOutputProto(outputFile string, metadataRule string) {
file, err := os.Create(outputFile)
data := "\n"
if err != nil {
log.Fatal(err)
}
var message proto.Message
if metadataRule == "test_spec" {
message = &test_spec_proto.TestSpec{}
} else if metadataRule == "code_metadata" {
message = &code_metadata_proto.CodeMetadata{}
}
data, err := proto.Marshal(message)
if err != nil {
log.Fatal(err)
}
@ -235,7 +244,7 @@ func main() {
inputFileData := strings.TrimRight(readFileToString(*inputFile), "\n")
filePaths := strings.Split(inputFileData, " ")
if len(filePaths) == 1 && filePaths[0] == "" {
writeNewlineToOutputFile(*outputFile)
writeEmptyOutputProto(*outputFile, *rule)
return
}
ownershipMetadataMap := &sync.Map{}

View file

@ -1 +0,0 @@