@@ -11,11 +11,11 @@ import (
1111 "github.com/compozy/gograph/engine/graph"
1212 "github.com/compozy/gograph/engine/infra"
1313 "github.com/compozy/gograph/engine/parser"
14+ "github.com/compozy/gograph/pkg/config"
1415 "github.com/compozy/gograph/pkg/errors"
1516 "github.com/compozy/gograph/pkg/logger"
1617 "github.com/compozy/gograph/pkg/progress"
1718 "github.com/spf13/cobra"
18- "github.com/spf13/viper"
1919)
2020
2121var analyzeCmd = & cobra.Command {
@@ -58,74 +58,72 @@ The resulting graph allows you to:
5858
5959 // Wrap the entire command execution with panic recovery
6060 return errors .WithRecover ("analyze_command" , func () error {
61+ // Load configuration
62+ cfg , err := config .Load ("" )
63+ if err != nil {
64+ return fmt .Errorf ("failed to load config: %w" , err )
65+ }
66+
67+ // Get project ID from config or override flag
68+ projectID := core .ID (cfg .Project .ID )
69+ if projectIDFlag , err := cmd .Flags ().GetString ("project-id" ); err == nil && projectIDFlag != "" {
70+ projectID = core .ID (projectIDFlag )
71+ }
72+
6173 // Check for --no-progress flag
6274 noProgress , err := cmd .Flags ().GetBool ("no-progress" )
6375 if err != nil {
6476 return fmt .Errorf ("failed to get no-progress flag: %w" , err )
6577 }
6678
67- // Initialize parser configuration from Viper
79+ // Initialize parser configuration from config
6880 parserConfig := & parser.Config {
69- IgnoreDirs : viper . GetStringSlice ( "parser.ignore_dirs" ) ,
70- IgnoreFiles : viper . GetStringSlice ( "parser.ignore_files" ) ,
71- IncludeTests : viper . GetBool ( "parser.include_tests" ) ,
72- IncludeVendor : viper . GetBool ( "parser.include_vendor" ) ,
73- MaxConcurrency : viper . GetInt ( "parser.max_concurrency" ) ,
81+ IgnoreDirs : cfg . Analysis . IgnoreDirs ,
82+ IgnoreFiles : cfg . Analysis . IgnoreFiles ,
83+ IncludeTests : cfg . Analysis . IncludeTests ,
84+ IncludeVendor : cfg . Analysis . IncludeVendor ,
85+ MaxConcurrency : cfg . Analysis . MaxConcurrency ,
7486 }
7587
76- // Initialize analyzer configuration from Viper
88+ // Initialize analyzer configuration with defaults
7789 analyzerConfig := analyzer .DefaultAnalyzerConfig ()
78- if maxDepth := viper .GetInt ("analyzer.max_dependency_depth" ); maxDepth > 0 {
79- analyzerConfig .MaxDependencyDepth = maxDepth
80- }
81- if ignoreTest := viper .GetBool ("analyzer.ignore_test_files" ); ignoreTest {
82- analyzerConfig .IgnoreTestFiles = ignoreTest
83- }
84- if ignoreVendor := viper .GetBool ("analyzer.ignore_vendor" ); ignoreVendor {
85- analyzerConfig .IgnoreVendor = ignoreVendor
86- }
87- if includeMetrics := viper .GetBool ("analyzer.include_metrics" ); includeMetrics {
88- analyzerConfig .IncludeMetrics = includeMetrics
89- }
90- if workers := viper .GetInt ("analyzer.parallel_workers" ); workers > 0 {
91- analyzerConfig .ParallelWorkers = workers
92- }
9390
94- // Initialize Neo4j configuration from Viper with fallback to defaults
95- neo4jURI := viper . GetString ( "neo4j.uri" )
91+ // Initialize Neo4j configuration from config with fallback to defaults
92+ neo4jURI := cfg . Neo4j . URI
9693 if neo4jURI == "" {
97- neo4jURI = DefaultNeo4jURI // Default only if not set via env vars
94+ neo4jURI = DefaultNeo4jURI
9895 }
99- neo4jUsername := viper . GetString ( "neo4j.username" )
96+ neo4jUsername := cfg . Neo4j . Username
10097 if neo4jUsername == "" {
101- neo4jUsername = DefaultNeo4jUsername // Default only if not set via env vars
98+ neo4jUsername = DefaultNeo4jUsername
10299 }
103- neo4jPassword := viper . GetString ( "neo4j.password" )
100+ neo4jPassword := cfg . Neo4j . Password
104101 if neo4jPassword == "" {
105- neo4jPassword = DefaultNeo4jPassword // Default only if not set via env vars
102+ neo4jPassword = DefaultNeo4jPassword
106103 }
107104
108105 neo4jConfig := & infra.Neo4jConfig {
109106 URI : neo4jURI ,
110107 Username : neo4jUsername ,
111108 Password : neo4jPassword ,
112- Database : viper . GetString ( "neo4j.database" ) ,
109+ Database : cfg . Neo4j . Database ,
113110 MaxRetries : 3 ,
114111 BatchSize : 1000 ,
115112 }
116113
117114 // Start the analysis
118115 if noProgress {
119- return runAnalysisWithoutProgress (projectPath , parserConfig , analyzerConfig , neo4jConfig )
116+ return runAnalysisWithoutProgress (projectPath , projectID , parserConfig , analyzerConfig , neo4jConfig )
120117 }
121118
122- return runAnalysisWithProgress (projectPath , parserConfig , analyzerConfig , neo4jConfig )
119+ return runAnalysisWithProgress (projectPath , projectID , parserConfig , analyzerConfig , neo4jConfig )
123120 })
124121 },
125122}
126123
127124func runAnalysisWithoutProgress (
128125 projectPath string ,
126+ projectID core.ID ,
129127 parserConfig * parser.Config ,
130128 analyzerConfig * analyzer.Config ,
131129 neo4jConfig * infra.Neo4jConfig ,
@@ -151,7 +149,6 @@ func runAnalysisWithoutProgress(
151149 // -----
152150 logger .Info ("analyzing project structure" )
153151 analyzerService := analyzer .NewAnalyzer (analyzerConfig )
154- projectID := core .NewID ()
155152 analysisInput := & analyzer.AnalysisInput {
156153 ProjectID : projectID .String (),
157154 Files : parseResult .Files ,
@@ -203,6 +200,7 @@ func runAnalysisWithoutProgress(
203200
204201func runAnalysisWithProgress (
205202 projectPath string ,
203+ projectID core.ID ,
206204 parserConfig * parser.Config ,
207205 analyzerConfig * analyzer.Config ,
208206 neo4jConfig * infra.Neo4jConfig ,
@@ -213,7 +211,6 @@ func runAnalysisWithProgress(
213211 var parseResult * parser.ParseResult
214212 var report * analyzer.AnalysisReport
215213 var graphResult * core.AnalysisResult
216- var projectID core.ID
217214
218215 // -----
219216 // Parsing Phase
@@ -233,7 +230,6 @@ func runAnalysisWithProgress(
233230 // -----
234231 err = progress .WithProgress ("Analyzing code structure" , func () error {
235232 analyzerService := analyzer .NewAnalyzer (analyzerConfig )
236- projectID = core .NewID ()
237233 analysisInput := & analyzer.AnalysisInput {
238234 ProjectID : projectID .String (),
239235 Files : parseResult .Files ,
@@ -298,7 +294,8 @@ func InitAnalyzeCommand() {
298294 initAnalyzeOnce .Do (func () {
299295 rootCmd .AddCommand (analyzeCmd )
300296
301- // Add progress flag
297+ // Add flags
302298 analyzeCmd .Flags ().Bool ("no-progress" , false , "Disable progress indicators" )
299+ analyzeCmd .Flags ().String ("project-id" , "" , "Override project ID from config file" )
303300 })
304301}
0 commit comments