1313 var output = GetValidOutputPath ( args . ElementAtOrDefault ( 1 ) ?? defaultOutput ) ;
1414
1515 var sw = Stopwatch . StartNew ( ) ;
16- var ( structure , contents ) = GetProjectInfo ( path ) ;
17- var content = BuildContent ( structure , contents ) ;
16+ var content = BuildContent ( path , config ) ;
1817 var stats = CalculateStats ( path , content , sw . Elapsed ) ;
1918
2019 WriteOutput ( output , content , config . OutputFormat ) ;
2726 Environment . Exit ( 1 ) ;
2827}
2928
30- static Config LoadConfig ( )
31- {
32- const string configPath = "config.json" ;
33- try
34- {
35- return File . Exists ( configPath )
36- ? JsonSerializer . Deserialize < Config > ( File . ReadAllText ( configPath ) ) ?? new Config ( )
37- : new Config ( ) ;
38- }
39- catch ( JsonException ex )
40- {
41- throw new InvalidOperationException ( "Error parsing config file" , ex ) ;
42- }
43- }
29+ static Config LoadConfig ( ) =>
30+ JsonSerializer . Deserialize < Config > (
31+ File . Exists ( "config.json" ) ? File . ReadAllText ( "config.json" ) : "{}"
32+ ) ?? new ( ) ;
4433
4534static string GetValidPath ( string defaultPath )
4635{
@@ -57,56 +46,49 @@ static string GetValidOutputPath(string defaultOutput)
5746 return string . IsNullOrWhiteSpace ( output ) ? defaultOutput : output ;
5847}
5948
60- static ( string structure , string contents ) GetProjectInfo ( string path )
49+ static string BuildContent ( string path , Config config )
6150{
6251 try
6352 {
64- return ( MyAppsContext . GetProjectStructure ( path ) , MyAppsContext . GetFileContents ( path ) ) ;
65- }
66- catch ( Exception ex )
67- {
68- throw new InvalidOperationException ( $ "Error processing project at { path } ", ex ) ;
69- }
70- }
53+ var sb = new StringBuilder ( ) ;
7154
72- static string BuildContent ( string structure , string contents ) =>
73- new StringBuilder ( )
74- . AppendLine ( "Project Structure:" )
75- . AppendLine ( structure )
76- . AppendLine ( "\n File Contents:" )
77- . AppendLine ( contents )
78- . ToString ( ) ;
55+ if ( config . IncludeStructure )
56+ {
57+ sb . AppendLine ( "Project Structure:" )
58+ . AppendLine ( MyAppsContext . GetProjectStructure ( path ) ) ;
59+ }
7960
80- static string CalculateStats ( string path , string content , TimeSpan timeTaken )
81- {
82- try
83- {
84- var fileCount = Directory . GetFiles ( path , "*" , SearchOption . AllDirectories ) . Length ;
85- var lineCount = content . Count ( c => c == '\n ' ) ;
86- return $ """
87- 📊 Stats:
88- 📁 Files processed: { fileCount }
89- 📝 Total lines: { lineCount }
90- ⏱️ Time taken: { timeTaken . TotalSeconds : F2} s
91- 💾 Output size: { content . Length } characters
92- """ ;
61+ if ( config . IncludeContents )
62+ {
63+ sb . AppendLine ( "\n File Contents:" )
64+ . AppendLine ( MyAppsContext . GetFileContents ( path ) ) ;
65+ }
66+
67+ return sb . ToString ( ) ;
9368 }
9469 catch ( Exception ex )
9570 {
96- throw new InvalidOperationException ( "Error calculating stats " , ex ) ;
71+ throw new InvalidOperationException ( $ "Error processing project at { path } ", ex ) ;
9772 }
9873}
9974
75+ static string CalculateStats ( string path , string content , TimeSpan timeTaken ) =>
76+ $ """
77+ 📊 Stats:
78+ 📁 Files processed: { Directory . GetFiles ( path , "*" , SearchOption . AllDirectories ) . Length }
79+ 📝 Total lines: { content . Count ( c => c == '\n ' ) }
80+ ⏱️ Time taken: { timeTaken . TotalSeconds : F2} s
81+ 💾 Output size: { content . Length } characters
82+ """ ;
83+
10084static void WriteOutput ( string output , string content , string format )
10185{
10286 try
10387 {
10488 var outputPath = Directory . Exists ( output ) ? Path . Combine ( output , "context.txt" ) : output ;
105- var formattedContent = format . ToLower ( ) switch
106- {
107- "json" => JsonSerializer . Serialize ( new { content , timestamp = DateTime . Now } ) ,
108- _ => content
109- } ;
89+ var formattedContent = format . ToLower ( ) == "json"
90+ ? JsonSerializer . Serialize ( new { content , timestamp = DateTime . Now } )
91+ : content ;
11092 File . WriteAllText ( outputPath , formattedContent ) ;
11193 }
11294 catch ( Exception ex )
@@ -120,4 +102,6 @@ record Config
120102 public string DefaultInputPath { get ; init ; } = "." ;
121103 public string DefaultOutputFileName { get ; init ; } = "context.txt" ;
122104 public string OutputFormat { get ; init ; } = "text" ;
105+ public bool IncludeStructure { get ; init ; } = true ;
106+ public bool IncludeContents { get ; init ; } = true ;
123107}
0 commit comments