22import pathlib
33import click
44
5- from .ingest import analyze_codebase , DEFAULT_IGNORE_PATTERNS , MAX_FILE_SIZE
5+ from gitingest .ingest import ingest
6+ from gitingest .ingest_from_query import MAX_FILE_SIZE
7+ from gitingest .parse_query import DEFAULT_IGNORE_PATTERNS
68
79def normalize_pattern (pattern : str ) -> str :
810 pattern = pattern .strip ()
@@ -12,61 +14,21 @@ def normalize_pattern(pattern: str) -> str:
1214 return pattern
1315
1416@click .command ()
15- @click .argument ('path ' , type = click . Path ( exists = True ) )
17+ @click .argument ('source ' , type = str , required = True )
1618@click .option ('--output' , '-o' , default = None , help = 'Output file path (default: <repo_name>.txt in current directory)' )
1719@click .option ('--max-size' , '-s' , default = MAX_FILE_SIZE , help = 'Maximum file size to process in bytes' )
18- @click .option ('--ignore-pattern' , '-i' , multiple = True , help = 'Additional patterns to ignore' )
19- def main (path , output , max_size , ignore_pattern ):
20+ @click .option ('--exclude-pattern' , '-e' , multiple = True , help = 'Patterns to exclude' )
21+ @click .option ('--include-pattern' , '-i' , multiple = True , help = 'Patterns to include' )
22+ def main (source , output , max_size , exclude_pattern , include_pattern ):
2023 """Analyze a directory and create a text dump of its contents."""
2124 try :
22- # Convert path to absolute path
23- abs_path = os .path .abspath (path )
24- repo_name = os .path .basename (abs_path )
25-
2625 # Combine default and custom ignore patterns
27- ignore_patterns = list (DEFAULT_IGNORE_PATTERNS )
28- if ignore_pattern :
29- ignore_patterns .extend (ignore_pattern )
30-
31- # Check for .gitignore and add its patterns
32- gitignore_path = os .path .join (abs_path , '.gitignore' )
33- if os .path .exists (gitignore_path ):
34- with open (gitignore_path , 'r' ) as f :
35- for line in f :
36- line = line .strip ()
37- # Skip empty lines and comments
38- if line and not line .startswith ('#' ):
39- normalized_pattern = normalize_pattern (line )
40- ignore_patterns .append (normalized_pattern )
41-
42- # If no output file specified, use repo name in current directory
43- if output is None :
44- output = f"{ repo_name } .txt"
45-
46- # Create a query dict to match the expected format
47- query = {
48- 'local_path' : abs_path ,
49- 'subpath' : '/' ,
50- 'user_name' : os .path .basename (os .path .dirname (abs_path )),
51- 'repo_name' : repo_name ,
52- 'ignore_patterns' : ignore_patterns ,
53- 'include_patterns' : [],
54- 'pattern_type' : 'exclude' ,
55- 'max_file_size' : max_size ,
56- 'branch' : None ,
57- 'commit' : None ,
58- 'type' : 'tree' ,
59- 'slug' : repo_name
60- }
61-
62- # Run analysis
63- summary , tree , content = analyze_codebase (query )
26+ exclude_patterns = list (exclude_pattern )
27+ include_patterns = list (set (include_pattern ))
6428
65- # Write to file
66- with open (output , 'w' ) as f :
67- f .write (f"Summary:\n { summary } \n \n " )
68- f .write (f"{ tree } \n " )
69- f .write (content )
29+ if not output :
30+ output = "digest.txt"
31+ summary , tree , content = ingest (source , max_size , include_patterns , exclude_patterns , output = output )
7032
7133 click .echo (f"Analysis complete! Output written to: { output } " )
7234 click .echo ("\n Summary:" )
0 commit comments