@@ -2,7 +2,6 @@ package cmd
22
33import (
44 "fmt"
5- "log"
65 "os"
76 "path/filepath"
87
@@ -11,6 +10,7 @@ import (
1110 "github.com/shivasurya/code-pathfinder/sourcecode-parser/graph/callgraph/builder"
1211 "github.com/shivasurya/code-pathfinder/sourcecode-parser/graph/callgraph/core"
1312 "github.com/shivasurya/code-pathfinder/sourcecode-parser/graph/callgraph/registry"
13+ "github.com/shivasurya/code-pathfinder/sourcecode-parser/output"
1414 "github.com/spf13/cobra"
1515)
1616
@@ -31,6 +31,17 @@ Examples:
3131 RunE : func (cmd * cobra.Command , args []string ) error {
3232 rulesPath , _ := cmd .Flags ().GetString ("rules" )
3333 projectPath , _ := cmd .Flags ().GetString ("project" )
34+ verbose , _ := cmd .Flags ().GetBool ("verbose" )
35+ debug , _ := cmd .Flags ().GetBool ("debug" )
36+
37+ // Setup logger with appropriate verbosity
38+ verbosity := output .VerbosityDefault
39+ if debug {
40+ verbosity = output .VerbosityDebug
41+ } else if verbose {
42+ verbosity = output .VerbosityVerbose
43+ }
44+ logger := output .NewLogger (verbosity )
3445
3546 if rulesPath == "" {
3647 return fmt .Errorf ("--rules flag is required" )
@@ -48,47 +59,47 @@ Examples:
4859 projectPath = absProjectPath
4960
5061 // Step 1: Build code graph (AST)
51- log . Printf ("Building code graph from %s...\n " , projectPath )
62+ logger . Progress ("Building code graph from %s..." , projectPath )
5263 codeGraph := graph .Initialize (projectPath )
5364 if len (codeGraph .Nodes ) == 0 {
5465 return fmt .Errorf ("no source files found in project" )
5566 }
56- log . Printf ("Code graph built: %d nodes\n " , len (codeGraph .Nodes ))
67+ logger . Statistic ("Code graph built: %d nodes" , len (codeGraph .Nodes ))
5768
5869 // Step 2: Build module registry
59- log . Printf ("Building module registry...\n " )
70+ logger . Progress ("Building module registry..." )
6071 moduleRegistry , err := registry .BuildModuleRegistry (projectPath )
6172 if err != nil {
62- log . Printf ( "Warning: failed to build module registry: %v\n " , err )
73+ logger . Warning ( " failed to build module registry: %v" , err )
6374 // Create empty registry as fallback
6475 moduleRegistry = core .NewModuleRegistry ()
6576 }
6677
6778 // Step 3: Build callgraph
68- log . Printf ("Building callgraph...\n " )
69- cg , err := builder .BuildCallGraph (codeGraph , moduleRegistry , projectPath )
79+ logger . Progress ("Building callgraph..." )
80+ cg , err := builder .BuildCallGraph (codeGraph , moduleRegistry , projectPath , logger )
7081 if err != nil {
7182 return fmt .Errorf ("failed to build callgraph: %w" , err )
7283 }
73- log . Printf ("Callgraph built: %d functions, %d call sites\n " ,
84+ logger . Statistic ("Callgraph built: %d functions, %d call sites" ,
7485 len (cg .Functions ), countTotalCallSites (cg ))
7586
7687 // Step 4: Load Python DSL rules
77- log . Printf ("Loading rules from %s...\n " , rulesPath )
88+ logger . Progress ("Loading rules from %s..." , rulesPath )
7889 loader := dsl .NewRuleLoader (rulesPath )
7990 rules , err := loader .LoadRules ()
8091 if err != nil {
8192 return fmt .Errorf ("failed to load rules: %w" , err )
8293 }
83- log . Printf ("Loaded %d rules\n " , len (rules ))
94+ logger . Statistic ("Loaded %d rules" , len (rules ))
8495
8596 // Step 5: Execute rules against callgraph
86- log . Printf ("\n === Running Security Scan ===\n " )
97+ logger . Progress ("\n === Running Security Scan ===" )
8798 totalDetections := 0
8899 for _ , rule := range rules {
89100 detections , err := loader .ExecuteRule (& rule , cg )
90101 if err != nil {
91- log . Printf ( "Error executing rule %s: %v\n " , rule .Rule .ID , err )
102+ logger . Error ( " executing rule %s: %v" , rule .Rule .ID , err )
92103 continue
93104 }
94105
@@ -99,8 +110,8 @@ Examples:
99110 }
100111
101112 // Step 6: Print summary
102- log . Printf ("\n === Scan Complete ===\n " )
103- log . Printf ("Total vulnerabilities found: %d\n " , totalDetections )
113+ logger . Progress ("\n === Scan Complete ===" )
114+ logger . Statistic ("Total vulnerabilities found: %d" , totalDetections )
104115
105116 if totalDetections > 0 {
106117 os .Exit (1 ) // Exit with error code if vulnerabilities found
@@ -143,6 +154,8 @@ func init() {
143154 rootCmd .AddCommand (scanCmd )
144155 scanCmd .Flags ().StringP ("rules" , "r" , "" , "Path to Python DSL rules file or directory (required)" )
145156 scanCmd .Flags ().StringP ("project" , "p" , "" , "Path to project directory to scan (required)" )
157+ scanCmd .Flags ().BoolP ("verbose" , "v" , false , "Show progress and statistics" )
158+ scanCmd .Flags ().Bool ("debug" , false , "Show debug diagnostics with timestamps" )
146159 scanCmd .MarkFlagRequired ("rules" )
147160 scanCmd .MarkFlagRequired ("project" )
148161}
0 commit comments