Skip to content

Commit 1766ffe

Browse files
committed
Fix Rust summarizer JSON parsing and path issues - Achieve 1:1 parity with Python version - Fix struct compatibility between parser and summarizer - Update Go CLI paths for correct binary locations - Remove Python dependencies completely - Enhanced call graph table with additional details
1 parent 2c2d2c7 commit 1766ffe

File tree

2 files changed

+856
-810
lines changed

2 files changed

+856
-810
lines changed

cmd/main.go

Lines changed: 97 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,97 @@
1-
package main
2-
3-
import (
4-
"encoding/json"
5-
"fmt"
6-
"os"
7-
"os/exec"
8-
"path/filepath"
9-
"strings"
10-
11-
"github.com/spf13/cobra"
12-
)
13-
14-
var verbose bool
15-
16-
func init() {
17-
analyzeCmd.Flags().BoolVar(&verbose, "verbose", false, "Enable verbose debug output")
18-
}
19-
20-
func main() {
21-
rootCmd := &cobra.Command{
22-
Use: "codesleuth",
23-
Short: "CodeSleuth is a multi-language code intelligence CLI tool",
24-
}
25-
26-
rootCmd.AddCommand(analyzeCmd)
27-
28-
if err := rootCmd.Execute(); err != nil {
29-
fmt.Println(err)
30-
os.Exit(1)
31-
}
32-
}
33-
34-
var analyzeCmd = &cobra.Command{
35-
Use: "analyze [path]",
36-
Short: "Analyze legacy code in the specified path",
37-
Args: cobra.MinimumNArgs(1),
38-
Run: func(cmd *cobra.Command, args []string) {
39-
root := args[0]
40-
var files []string
41-
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
42-
if err != nil {
43-
return err
44-
}
45-
ext := strings.ToLower(filepath.Ext(path))
46-
if !info.IsDir() && (ext == ".cob" || ext == ".cbl" || ext == ".cobol") {
47-
files = append(files, path)
48-
}
49-
return nil
50-
})
51-
if err != nil {
52-
fmt.Printf("Error walking the path %q: %v\n", root, err)
53-
return
54-
}
55-
fmt.Printf("Found %d COBOL files:\n", len(files))
56-
for _, f := range files {
57-
fmt.Println(f)
58-
parserArgs := []string{"..\\parser\\target\\release\\parser", f}
59-
if verbose {
60-
parserArgs = append(parserArgs, "--verbose")
61-
}
62-
cmd := exec.Command(parserArgs[0], parserArgs[1:]...)
63-
output, err := cmd.Output()
64-
if err != nil {
65-
fmt.Printf("Error running parser on %s: %v\n", f, err)
66-
continue
67-
}
68-
var ir struct {
69-
ProgramName string `json:"program_name"`
70-
SourceFile string `json:"source_file"`
71-
}
72-
if err := json.Unmarshal(output, &ir); err != nil {
73-
fmt.Printf("Error parsing IR JSON for %s: %v\n", f, err)
74-
continue
75-
}
76-
fmt.Printf("Parsed: %s (program_name: %s)\n", ir.SourceFile, ir.ProgramName)
77-
78-
// Call Rust summarizer binary
79-
sumCmd := exec.Command("..\\summarizer\\target\\release\\summarizer")
80-
sumIn, err := sumCmd.StdinPipe()
81-
if err != nil {
82-
fmt.Printf("Error getting stdin pipe for Rust summarizer for %s: %v\n", f, err)
83-
continue
84-
}
85-
go func() {
86-
sumIn.Write(output)
87-
sumIn.Close()
88-
}()
89-
summary, err := sumCmd.CombinedOutput()
90-
if err != nil {
91-
fmt.Printf("Rust summarizer failed for %s: %v\n", f, err)
92-
}
93-
fmt.Println(string(summary))
94-
}
95-
// TODO: Call Rust parser and Python pipeline here
96-
},
97-
}
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"os"
7+
"os/exec"
8+
"path/filepath"
9+
"strings"
10+
11+
"github.com/spf13/cobra"
12+
)
13+
14+
var verbose bool
15+
16+
func init() {
17+
analyzeCmd.Flags().BoolVar(&verbose, "verbose", false, "Enable verbose debug output")
18+
}
19+
20+
func main() {
21+
rootCmd := &cobra.Command{
22+
Use: "codesleuth",
23+
Short: "CodeSleuth is a multi-language code intelligence CLI tool",
24+
}
25+
26+
rootCmd.AddCommand(analyzeCmd)
27+
28+
if err := rootCmd.Execute(); err != nil {
29+
fmt.Println(err)
30+
os.Exit(1)
31+
}
32+
}
33+
34+
var analyzeCmd = &cobra.Command{
35+
Use: "analyze [path]",
36+
Short: "Analyze legacy code in the specified path",
37+
Args: cobra.MinimumNArgs(1),
38+
Run: func(cmd *cobra.Command, args []string) {
39+
root := args[0]
40+
var files []string
41+
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
42+
if err != nil {
43+
return err
44+
}
45+
ext := strings.ToLower(filepath.Ext(path))
46+
if !info.IsDir() && (ext == ".cob" || ext == ".cbl" || ext == ".cobol") {
47+
files = append(files, path)
48+
}
49+
return nil
50+
})
51+
if err != nil {
52+
fmt.Printf("Error walking the path %q: %v\n", root, err)
53+
return
54+
}
55+
fmt.Printf("Found %d COBOL files:\n", len(files))
56+
for _, f := range files {
57+
fmt.Println(f)
58+
parserArgs := []string{"..\\parser\\target\\release\\parser.exe", f}
59+
if verbose {
60+
parserArgs = append(parserArgs, "--verbose")
61+
}
62+
cmd := exec.Command(parserArgs[0], parserArgs[1:]...)
63+
output, err := cmd.Output()
64+
if err != nil {
65+
fmt.Printf("Error running parser on %s: %v\n", f, err)
66+
continue
67+
}
68+
var ir struct {
69+
ProgramName string `json:"program_name"`
70+
SourceFile string `json:"source_file"`
71+
}
72+
if err := json.Unmarshal(output, &ir); err != nil {
73+
fmt.Printf("Error parsing IR JSON for %s: %v\n", f, err)
74+
continue
75+
}
76+
fmt.Printf("Parsed: %s (program_name: %s)\n", ir.SourceFile, ir.ProgramName)
77+
78+
// Call Rust summarizer binary
79+
sumCmd := exec.Command("..\\summarizer\\target\\release\\summarizer.exe")
80+
sumIn, err := sumCmd.StdinPipe()
81+
if err != nil {
82+
fmt.Printf("Error getting stdin pipe for Rust summarizer for %s: %v\n", f, err)
83+
continue
84+
}
85+
go func() {
86+
sumIn.Write(output)
87+
sumIn.Close()
88+
}()
89+
summary, err := sumCmd.CombinedOutput()
90+
if err != nil {
91+
fmt.Printf("Rust summarizer failed for %s: %v\n", f, err)
92+
}
93+
fmt.Println(string(summary))
94+
}
95+
// TODO: Call Rust parser and Python pipeline here
96+
},
97+
}

0 commit comments

Comments
 (0)