Skip to content

Commit

Permalink
Added output file format (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
shivasurya authored May 12, 2024
1 parent 27c2484 commit e7f4fca
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ example-java-project/
main
sourcecode-parser/sourcecode-parser
.idea/
*.json
23 changes: 22 additions & 1 deletion sourcecode-parser/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func executeProject(project, query, output string, stdin bool) (string, error) {
func main() {
// accept command line param optional path to source code
output := flag.String("output", "", "Supported output format: json")
outputFile := flag.String("output-file", "", "Output file path")
query := flag.String("query", "", "Query to execute")
project := flag.String("project", "", "Project to analyze")
stdin := flag.Bool("stdin", false, "Read query from stdin")
Expand All @@ -81,5 +82,25 @@ func main() {
fmt.Println(err)
return
}
fmt.Println(result)
if *outputFile != "" {
file, err := os.Create(*outputFile)
if err != nil {
fmt.Println("Error creating output file: ", err)
return
}
defer func(file *os.File) {
err := file.Close()
if err != nil {
fmt.Println("Error closing output file: ", err)
return
}
}(file)
_, err = file.WriteString(result)
if err != nil {
fmt.Println("Error writing output file: ", err)
return
}
} else {
fmt.Println(result)
}
}

0 comments on commit e7f4fca

Please sign in to comment.