Skip to content

Commit c3c7d99

Browse files
committed
πŸ›πŸ”§ Fixed & improved git commands functionality.
1 parent c4bad62 commit c3c7d99

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

β€Žsrc/main.rs

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use colored::Colorize;
1717
use gpt_api::query;
1818

1919
use crate::{
20-
command_utils::{parse_command, parse_commands, run_commands},
20+
command_utils::{parse_command, parse_commands},
2121
git::{build_commands, Git},
2222
gpt_api::init,
2323
utils::{check_for_update, get_executable_name},
@@ -233,8 +233,20 @@ async fn main() {
233233
std::io::stdin().read_line(&mut input).unwrap();
234234
println!("");
235235
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+
238250
std::process::exit(0);
239251
} else if input.trim() == "n" || input.trim() == "N" {
240252
println!("{}", "Aborted".red());
@@ -246,27 +258,44 @@ async fn main() {
246258

247259
let loader = utils::Loader::new("Waiting for response from GPT-3");
248260

249-
let result = query(None, &git, args).await;
261+
let result = query(None, &git, args.clone()).await;
250262

251263
loader.stop();
252264

253265
let result = match result {
254-
Ok(result) => build_commands(result, push),
266+
Ok(result) => result,
255267
Err(err) => {
256268
println!("Error: {}", err);
257269
return;
258270
}
259271
};
260272

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);
262276

263277
println!("{}\n{}", "Commands:".bright_magenta(), parsed_command);
264278
print!("\n{} {}: ", "Confirm".green(), "(Y/n)");
265279
let mut input = String::new();
266280
std::io::stdin().read_line(&mut input).unwrap();
267281
println!("");
268282
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+
270299
std::process::exit(0);
271300
} else if input.trim() == "n" || input.trim() == "N" {
272301
println!("{}", "Aborted".red());

0 commit comments

Comments
Β (0)