6
6
use anyhow:: { Context , Result } ;
7
7
use clap:: Parser ;
8
8
use code2prompt:: {
9
- copy_to_clipboard, get_model_info, get_tokenizer, get_git_diff, get_git_diff_between_branches, get_git_log,
10
- handle_undefined_variables, handlebars_setup, label, render_template, traverse_directory, write_to_file,
9
+ copy_to_clipboard, get_git_diff, get_git_diff_between_branches, get_git_log, get_model_info,
10
+ get_tokenizer, handle_undefined_variables, handlebars_setup, label, render_template,
11
+ traverse_directory, write_to_file,
11
12
} ;
12
13
use colored:: * ;
13
14
use indicatif:: { ProgressBar , ProgressStyle } ;
@@ -41,7 +42,7 @@ struct Cli {
41
42
42
43
/// Exclude files/folders from the source tree based on exclude patterns
43
44
#[ clap( long) ]
44
- exclude_from_tree : bool ,
45
+ exclude_from_tree : bool ,
45
46
46
47
/// Display the token count of the generated prompt
47
48
#[ clap( long) ]
@@ -91,7 +92,7 @@ struct Cli {
91
92
92
93
/// Print output as JSON
93
94
#[ clap( long) ]
94
- json : bool ,
95
+ json : bool ,
95
96
}
96
97
97
98
fn main ( ) -> Result < ( ) > {
@@ -153,7 +154,8 @@ fn main() -> Result<()> {
153
154
error ! ( "Please provide exactly two branches separated by a comma." ) ;
154
155
std:: process:: exit ( 1 ) ;
155
156
}
156
- git_diff_branch = get_git_diff_between_branches ( & args. path , & branches[ 0 ] , & branches[ 1 ] ) . unwrap_or_default ( )
157
+ git_diff_branch = get_git_diff_between_branches ( & args. path , & branches[ 0 ] , & branches[ 1 ] )
158
+ . unwrap_or_default ( )
157
159
}
158
160
159
161
// git diff two get_git_diff_between_branches
@@ -169,7 +171,7 @@ fn main() -> Result<()> {
169
171
}
170
172
171
173
spinner. finish_with_message ( "Done!" . green ( ) . to_string ( ) ) ;
172
-
174
+
173
175
// Prepare JSON Data
174
176
let mut data = json ! ( {
175
177
"absolute_code_path" : label( & args. path) ,
@@ -199,8 +201,13 @@ fn main() -> Result<()> {
199
201
0
200
202
} ;
201
203
202
- let paths: Vec < String > = files. iter ( )
203
- . filter_map ( |file| file. get ( "path" ) . and_then ( |p| p. as_str ( ) ) . map ( |s| s. to_string ( ) ) )
204
+ let paths: Vec < String > = files
205
+ . iter ( )
206
+ . filter_map ( |file| {
207
+ file. get ( "path" )
208
+ . and_then ( |p| p. as_str ( ) )
209
+ . map ( |s| s. to_string ( ) )
210
+ } )
204
211
. collect ( ) ;
205
212
206
213
let model_info = get_model_info ( & args. encoding ) ;
@@ -230,7 +237,27 @@ fn main() -> Result<()> {
230
237
231
238
// Copy to Clipboard
232
239
if !args. no_clipboard {
233
- copy_to_clipboard ( & rendered) ?;
240
+ match copy_to_clipboard ( & rendered) {
241
+ Ok ( _) => {
242
+ println ! (
243
+ "{}{}{} {}" ,
244
+ "[" . bold( ) . white( ) ,
245
+ "✓" . bold( ) . green( ) ,
246
+ "]" . bold( ) . white( ) ,
247
+ "Copied to clipboard successfully." . green( )
248
+ ) ;
249
+ }
250
+ Err ( e) => {
251
+ eprintln ! (
252
+ "{}{}{} {}" ,
253
+ "[" . bold( ) . white( ) ,
254
+ "!" . bold( ) . red( ) ,
255
+ "]" . bold( ) . white( ) ,
256
+ format!( "Failed to copy to clipboard: {}" , e) . red( )
257
+ ) ;
258
+ println ! ( "{}" , & rendered) ;
259
+ }
260
+ }
234
261
}
235
262
236
263
// Output File
0 commit comments