11use clap:: Parser ;
2- use git2prompt:: process_github_urls;
2+ use git2prompt:: { process_github_urls, process_local_path } ;
33use std:: path:: PathBuf ;
44
5- /// A command-line tool to download GitHub repository contents and format them for AI tools.
5+ /// A command-line tool to process repository contents and format them for AI tools.
66#[ derive( Parser , Debug ) ]
77#[ clap( author, version, about, long_about = None ) ]
88struct Args {
9- /// GitHub repository URLs (e.g., "owner/repo"). Supports multiple URLs .
9+ /// GitHub repository URLs (e.g., "owner/repo") or a single local path with --local .
1010 #[ clap( required = true ) ]
11- urls : Vec < String > ,
11+ sources : Vec < String > ,
12+
13+ /// Process the source as a local directory path instead of a GitHub URL.
14+ #[ clap( short, long, action) ]
15+ local : bool ,
1216
1317 /// Do not add file paths as headers above code blocks in the output file(s).
1418 #[ clap( short, long, action) ]
1519 no_headers : bool ,
1620
1721 /// Merge contents of all repositories into a single output file.
18- /// If not set, a separate file will be created for each repository .
19- #[ clap( short, long, action) ]
22+ /// Incompatible with --local .
23+ #[ clap( short, long, action, conflicts_with = "local" ) ]
2024 merge_files : bool ,
2125
2226 /// Path to a file containing a list of files/folders to ignore.
@@ -28,12 +32,13 @@ struct Args {
2832 ) ]
2933 ignore_file : PathBuf ,
3034
31- /// Download and process only a specific folder within the repository
35+ /// Download and process only a specific folder within the repository.
3236 #[ clap( short, long, value_name = "FOLDER PATH" , conflicts_with = "pr" ) ]
3337 folder : Option < String > ,
3438
35- /// Process only the files changed in a specific pull request
36- #[ clap( long, value_name = "PULL REQUEST NUMBER" , conflicts_with = "folder" ) ]
39+ /// Process only the files changed in a specific pull request.
40+ /// Incompatible with --local.
41+ #[ clap( long, value_name = "PULL REQUEST NUMBER" , conflicts_with_all = [ "folder" , "local" ] ) ]
3742 pr : Option < u32 > ,
3843}
3944
@@ -42,25 +47,48 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
4247 let args = Args :: parse ( ) ;
4348
4449 println ! ( "Starting git2prompt..." ) ;
45- println ! ( "Repositories to process: {:?}" , args. urls) ;
46- println ! ( "No file headers: {}" , args. no_headers) ;
47- println ! ( "Merge into a single output file: {}" , args. merge_files) ;
48- println ! ( "Ignore file path: {:?}" , args. ignore_file) ;
49- println ! ( "Folder to process: {:?}" , args. folder) ;
50- println ! ( "Pull request number: {:?}" , args. pr) ;
51- println ! ( "----------------------------------------" ) ;
5250
53- // Call the library function to process the URLs, wrapping the ignore file path in Some
54- match process_github_urls (
55- args. urls ,
56- args. no_headers ,
57- args. merge_files ,
58- Some ( args. ignore_file ) ,
59- args. folder ,
60- args. pr ,
61- )
62- . await
63- {
51+ let result = if args. local {
52+ // --- LOCAL PATH MODE ---
53+ if args. sources . len ( ) != 1 {
54+ // Using Box::from to create a valid error type
55+ return Err ( Box :: from (
56+ "Error: When using --local, exactly one directory path must be provided." ,
57+ ) ) ;
58+ }
59+ let local_path = PathBuf :: from ( & args. sources [ 0 ] ) ;
60+ println ! ( "Processing local repository at: {:?}" , local_path) ;
61+ println ! ( "No file headers: {}" , args. no_headers) ;
62+ println ! ( "Ignore file path: {:?}" , args. ignore_file) ;
63+ println ! ( "----------------------------------------" ) ;
64+ process_local_path (
65+ local_path,
66+ args. no_headers ,
67+ Some ( args. ignore_file ) ,
68+ args. folder ,
69+ )
70+ . await
71+ } else {
72+ // --- GITHUB URL MODE (default) ---
73+ println ! ( "Repositories to process: {:?}" , args. sources) ;
74+ println ! ( "No file headers: {}" , args. no_headers) ;
75+ println ! ( "Merge into a single output file: {}" , args. merge_files) ;
76+ println ! ( "Ignore file path: {:?}" , args. ignore_file) ;
77+ println ! ( "Folder to process: {:?}" , args. folder) ;
78+ println ! ( "Pull request number: {:?}" , args. pr) ;
79+ println ! ( "----------------------------------------" ) ;
80+ process_github_urls (
81+ args. sources ,
82+ args. no_headers ,
83+ args. merge_files ,
84+ Some ( args. ignore_file ) ,
85+ args. folder ,
86+ args. pr ,
87+ )
88+ . await
89+ } ;
90+
91+ match result {
6492 Ok ( output_paths) => {
6593 println ! ( "Processing complete. Output files created:" ) ;
6694 for path in output_paths {
@@ -73,4 +101,4 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
73101 Err ( e. into ( ) )
74102 }
75103 }
76- }
104+ }
0 commit comments