feat(go-analyzer): add CLI entry point
This commit is contained in:
48
tools/go-analyzer/main.go
Normal file
48
tools/go-analyzer/main.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
sourceDir := flag.String("source", "", "Path to Go source root (e.g., ../../golang/nats-server)")
|
||||
dbPath := flag.String("db", "", "Path to SQLite database file (e.g., ../../porting.db)")
|
||||
schemaPath := flag.String("schema", "", "Path to SQL schema file (e.g., ../../porting-schema.sql)")
|
||||
flag.Parse()
|
||||
|
||||
if *sourceDir == "" || *dbPath == "" || *schemaPath == "" {
|
||||
fmt.Fprintf(os.Stderr, "Usage: go-analyzer --source <path> --db <path> --schema <path>\n")
|
||||
flag.PrintDefaults()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Open DB and apply schema
|
||||
db, err := OpenDB(*dbPath, *schemaPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to open database: %v", err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
// Run analysis
|
||||
analyzer := NewAnalyzer(*sourceDir)
|
||||
result, err := analyzer.Analyze()
|
||||
if err != nil {
|
||||
log.Fatalf("Analysis failed: %v", err)
|
||||
}
|
||||
|
||||
// Write to DB
|
||||
writer := NewDBWriter(db)
|
||||
if err := writer.WriteAll(result); err != nil {
|
||||
log.Fatalf("Failed to write results: %v", err)
|
||||
}
|
||||
|
||||
fmt.Printf("Analysis complete:\n")
|
||||
fmt.Printf(" Modules: %d\n", len(result.Modules))
|
||||
fmt.Printf(" Features: %d\n", result.TotalFeatures())
|
||||
fmt.Printf(" Unit Tests: %d\n", result.TotalTests())
|
||||
fmt.Printf(" Dependencies: %d\n", len(result.Dependencies))
|
||||
fmt.Printf(" Imports: %d\n", len(result.Imports))
|
||||
}
|
||||
Reference in New Issue
Block a user