@@ -17,7 +17,7 @@ use colored::Colorize;
17
17
use gpt_api:: query;
18
18
19
19
use crate :: {
20
- command_utils:: { parse_command, parse_commands, run_commands } ,
20
+ command_utils:: { parse_command, parse_commands} ,
21
21
git:: { build_commands, Git } ,
22
22
gpt_api:: init,
23
23
utils:: { check_for_update, get_executable_name} ,
@@ -233,8 +233,20 @@ async fn main() {
233
233
std:: io:: stdin ( ) . read_line ( & mut input) . unwrap ( ) ;
234
234
println ! ( "" ) ;
235
235
if input. trim ( ) == "y" || input. trim ( ) == "" || input. trim ( ) == "Y" {
236
- let commands = build_commands ( "Created README.md" . to_owned ( ) , push) ;
237
- run_commands ( & commands) ;
236
+ git. add_all ( Some ( & args) ) ;
237
+ let commit_result = git. commit ( & "Created README.md" . to_owned ( ) ) ;
238
+
239
+ if commit_result. is_err ( ) {
240
+ println ! ( "{} {}" , "Error:" . red( ) , commit_result. unwrap_err( ) ) ;
241
+ std:: process:: exit ( 1 ) ;
242
+ }
243
+
244
+ println ! ( "{} {}" , "Committed:" . bright_green( ) , "Created README.md" ) ;
245
+
246
+ if push {
247
+ git. push ( ) ;
248
+ }
249
+
238
250
std:: process:: exit ( 0 ) ;
239
251
} else if input. trim ( ) == "n" || input. trim ( ) == "N" {
240
252
println ! ( "{}" , "Aborted" . red( ) ) ;
@@ -246,27 +258,44 @@ async fn main() {
246
258
247
259
let loader = utils:: Loader :: new ( "Waiting for response from GPT-3" ) ;
248
260
249
- let result = query ( None , & git, args) . await ;
261
+ let result = query ( None , & git, args. clone ( ) ) . await ;
250
262
251
263
loader. stop ( ) ;
252
264
253
265
let result = match result {
254
- Ok ( result) => build_commands ( result, push ) ,
266
+ Ok ( result) => result,
255
267
Err ( err) => {
256
268
println ! ( "Error: {}" , err) ;
257
269
return ;
258
270
}
259
271
} ;
260
272
261
- let parsed_command = parse_commands ( & result, true ) ;
273
+ let command = build_commands ( & result, push, & args) ;
274
+
275
+ let parsed_command = parse_commands ( & command, true ) ;
262
276
263
277
println ! ( "{}\n {}" , "Commands:" . bright_magenta( ) , parsed_command) ;
264
278
print ! ( "\n {} {}: " , "Confirm" . green( ) , "(Y/n)" ) ;
265
279
let mut input = String :: new ( ) ;
266
280
std:: io:: stdin ( ) . read_line ( & mut input) . unwrap ( ) ;
267
281
println ! ( "" ) ;
268
282
if input. trim ( ) == "y" || input. trim ( ) == "Y" || input. trim ( ) == "" {
269
- run_commands ( & result) ;
283
+ git. add_all ( Some ( & args) ) ;
284
+ let commit_result = git. commit ( & result) ;
285
+
286
+ if commit_result. is_err ( ) {
287
+ println ! ( "{} {}" , "Error:" . red( ) , commit_result. unwrap_err( ) ) ;
288
+ std:: process:: exit ( 1 ) ;
289
+ }
290
+
291
+ println ! ( "{}" , commit_result. unwrap( ) . to_string( ) ) ;
292
+
293
+ println ! ( "{} {}" , "Committed:" . bright_green( ) , result) ;
294
+
295
+ if push {
296
+ git. push ( ) ;
297
+ }
298
+
270
299
std:: process:: exit ( 0 ) ;
271
300
} else if input. trim ( ) == "n" || input. trim ( ) == "N" {
272
301
println ! ( "{}" , "Aborted" . red( ) ) ;
0 commit comments