Skip to content

Commit

Permalink
cli: add debug flag
Browse files Browse the repository at this point in the history
  • Loading branch information
z7zmey committed Oct 15, 2017
1 parent 4d7b033 commit 17fe6d6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
4 changes: 4 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (i *ArrayFlags) Set(value string) error {
type CGConfig struct {
path ArrayFlags
exclude ArrayFlags
debug bool
}

var Config = CGConfig{}
Expand All @@ -47,5 +48,8 @@ func ParseConfigFlags() {
flag.Var(&Config.exclude, "exclude", "exclude path")
flag.Var(&Config.exclude, "e", "exclude path (shorthand)")

flag.BoolVar(&Config.debug, "debug", false, "print debug info")
flag.BoolVar(&Config.debug, "d", false, "print debug info (shorthand)")

flag.Parse()
}
18 changes: 13 additions & 5 deletions path.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,12 @@ func ProcessPath() {

func processFileAst(codeGraphDir string, files chan string, wg *sync.WaitGroup) {
for file := range files {
fmt.Printf("proces ast for: %s\n", file)
cmd := exec.Command("php", codeGraphDir+"/php-worker/worker.php", "--file", file)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if Config.debug {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
}
cmd.Run()
cmd.Wait()
wg.Done()
Expand All @@ -111,9 +114,12 @@ func processFileAst(codeGraphDir string, files chan string, wg *sync.WaitGroup)

func processFileCfg(codeGraphDir string, files chan string) {
for file := range files {
fmt.Printf("proces cfg for: %s\n", file)
cmd := exec.Command("php", codeGraphDir+"/php-worker/worker.php", "--file", file, "--cfg")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if Config.debug {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
}
cmd.Run()
}
}
Expand Down Expand Up @@ -153,7 +159,9 @@ func setMethodImplementations(method AstMethod) {
qw := graph.NewWriter(store)
id, err := schema.WriteAsQuads(qw, method)
checkErr(err)
fmt.Printf("saving abstract method implementations %s: %+v\n", id, method)
if (Config.debug) {
fmt.Printf("saving abstract method implementations %s: %+v\n", id, method)
}

err = qw.Flush()
checkErr(err)
Expand Down
31 changes: 25 additions & 6 deletions socketServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,46 +95,65 @@ func handleRequest(connections chan net.Conn) {
}

func handleMessage(msg Message) {
fmt.Printf("process message: %+v\n", msg)
if Config.debug {
fmt.Printf("process message: %+v\n", msg)
}

qw := graph.NewWriter(store)

for _, astFile := range msg.Files {
var id, err = schema.WriteAsQuads(qw, astFile)
checkErr(err)
fmt.Printf("saving %s: %+v\n", id, astFile)

if Config.debug {
fmt.Printf("saving %s: %+v\n", id, astFile)
}

CacheClear()
}

for _, AstClass := range msg.Classes {
var id, err = schema.WriteAsQuads(qw, AstClass)
checkErr(err)
fmt.Printf("saving %s: %+v\n", id, AstClass)

if Config.debug {
fmt.Printf("saving %s: %+v\n", id, AstClass)
}

CacheClear()
}

for _, astInterface := range msg.Interfaces {
var id, err = schema.WriteAsQuads(qw, astInterface)
checkErr(err)
fmt.Printf("saving %s: %+v\n", id, astInterface)

if Config.debug {
fmt.Printf("saving %s: %+v\n", id, astInterface)
}

CacheClear()
}

for _, astMethod := range msg.Methods {
var id, err = schema.WriteAsQuads(qw, astMethod)
checkErr(err)
fmt.Printf("saving %s: %+v\n", id, astMethod)

if Config.debug {
fmt.Printf("saving %s: %+v\n", id, astMethod)
}

CacheClear()
}

for _, astProperty := range msg.Properties {
var id, err = schema.WriteAsQuads(qw, astProperty)
checkErr(err)
fmt.Printf("saving %s: %+v\n", id, astProperty)

if Config.debug {
fmt.Printf("saving %s: %+v\n", id, astProperty)
}

CacheClear()
}

err := qw.Close()
Expand Down

0 comments on commit 17fe6d6

Please sign in to comment.