Brijesh's Git Server — gitcc @ 989a633d27f73f5b5eb5af65a3ef109db8a1cf07

failed attempt at automatic git workflow

fix: handle selection.is_none condition within select function
Brijesh Wawdhane brijesh@wawdhane.com
Mon, 25 Sep 2023 14:29:10 +0530
commit

989a633d27f73f5b5eb5af65a3ef109db8a1cf07

parent

6d5984e44c3caac3b4552b9f0b0db124a110bca9

4 files changed, 25 insertions(+), 21 deletions(-)

jump to
M src/git_actions.rssrc/git_actions.rs

@@ -13,12 +13,18 @@ .output()

.expect("Failed to commit changes."); } -pub fn git_add_all() { - Command::new("git") +pub fn confirm_and_stage_all() { + let staging_options: [&str; 2] = ["Yes", "No"]; + let staging_choice_number: Option<usize> = select_option(&staging_options); + let staging_choice: String = staging_options[staging_choice_number.unwrap()].to_string(); + + if staging_choice == "Yes" { + Command::new("git") .arg("add") .arg("-A") .output() .expect("Failed to add files."); + } } pub fn make_initial_commit() {

@@ -27,16 +33,10 @@ "Use default initial commit message",

"Create custom initial commit message", ]; - let commit_message_choice: Option<usize> = select_option(&commit_message_options); - if commit_message_choice.is_none() { - println!("Please choose a commit message option"); - std::process::exit(1); - } - - let commit_message_choice_number: usize = commit_message_choice.unwrap(); + let commit_message_choice_number: Option<usize> = select_option(&commit_message_options); let commit_message_choice: String = - commit_message_options[commit_message_choice_number].to_string(); + commit_message_options[commit_message_choice_number.unwrap()].to_string(); let commit_type: String; let commit_message: String;

@@ -49,6 +49,6 @@ commit_type = String::from("chore");

commit_message = String::from("initial commit"); } - git_add_all(); + confirm_and_stage_all(); make_commit(commit_type, commit_message); -} +}
M src/inputs.rssrc/inputs.rs

@@ -5,14 +5,9 @@ let commit_type_options: [&str; 8] = [

"feat", "fix", "docs", "style", "refactor", "test", "chore", "revert", ]; - let commit_type_choice: Option<usize> = select_option(&commit_type_options); + let commit_type_choice_number: Option<usize> = select_option(&commit_type_options); - if commit_type_choice.is_none() { - println!("Please choose a commit type"); - std::process::exit(1); - } - - let commit_type_choice: String = commit_type_options[commit_type_choice.unwrap()].to_string(); + let commit_type_choice: String = commit_type_options[commit_type_choice_number.unwrap()].to_string(); return commit_type_choice; }
M src/main.rssrc/main.rs

@@ -7,7 +7,7 @@ mod inputs;

mod utils; use git_actions::*; -// use inputs::*; +use inputs::*; // use utils::*; fn main() {

@@ -22,7 +22,11 @@ if rev_parse_single.is_err() {

println!("No commits yet"); make_initial_commit(); } else { - print!("There are commits"); + let commit_type: String = get_commit_type(); + let commit_message: String = get_commit_message(); + + confirm_and_stage_all(); + make_commit(commit_type, commit_message); } } else { println!("Not a git repository");
M src/utils.rssrc/utils.rs

@@ -8,5 +8,10 @@ .items(options)

.interact_opt() .unwrap(); + if selection.is_none() { + println!("Please choose an option"); + std::process::exit(1); + } + return selection; }