Brijesh's Git Server — gitcc @ e842b23b5d9b80521bf8425c845deb83efb13d9f

failed attempt at automatic git workflow

feat: add message to select function
Brijesh Wawdhane brijesh@wawdhane.com
Mon, 25 Sep 2023 14:58:56 +0530
commit

e842b23b5d9b80521bf8425c845deb83efb13d9f

parent

6e9c8b27caead7a7c0ed64f134ef90979e06be3b

3 files changed, 16 insertions(+), 14 deletions(-)

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

@@ -17,7 +17,8 @@ }

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_number: Option<usize> = + select_option("Would you like to stage all files", &staging_options); let staging_choice: String = staging_options[staging_choice_number.unwrap()].to_string(); if staging_choice == "Yes" {

@@ -32,7 +33,8 @@

// function to push to remote pub fn confirm_and_push_to_remote() { let push_options: [&str; 2] = ["Yes", "No"]; - let push_choice_number: Option<usize> = select_option(&push_options); + let push_choice_number: Option<usize> = + select_option("Would you like to push to remote?", &push_options); let push_choice: String = push_options[push_choice_number.unwrap()].to_string(); if push_choice == "Yes" {

@@ -44,7 +46,8 @@ for remote in &remotes_string_array {

remotes.push(remote.unwrap().to_string()); } - let remote_choice_number: Option<usize> = select_option_string_vec(&remotes); + let remote_choice_number: Option<usize> = + select_option_string_vec("Select a remote to push to", &remotes); let remote_choice: String = remotes[remote_choice_number.unwrap()].to_string(); // TODO: ask user to choose branch

@@ -60,12 +63,10 @@ }

} pub fn make_initial_commit() { - let commit_message_options: [&str; 2] = [ - "Use default initial commit message", - "Create custom initial commit message", - ]; + let commit_message_options: [&str; 2] = ["Use default", "Create custom"]; - let commit_message_choice_number: Option<usize> = select_option(&commit_message_options); + let commit_message_choice_number: Option<usize> = + select_option("Choose initial commit message", &commit_message_options); let commit_message_choice: String = commit_message_options[commit_message_choice_number.unwrap()].to_string();

@@ -73,7 +74,7 @@

let commit_type: String; let commit_message: String; - if commit_message_choice == "Create custom initial commit message" { + if commit_message_choice == "Create custom" { commit_type = get_commit_type(); commit_message = get_commit_message(); } else {
M src/inputs.rssrc/inputs.rs

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

"feat", "fix", "docs", "style", "refactor", "test", "chore", "revert", ]; - let commit_type_choice_number: Option<usize> = select_option(&commit_type_options); + let commit_type_choice_number: Option<usize> = + select_option("Select type of change in this commit", &commit_type_options); let commit_type_choice: String = commit_type_options[commit_type_choice_number.unwrap()].to_string();
M src/utils.rssrc/utils.rs

@@ -1,8 +1,8 @@

use dialoguer::{theme::ColorfulTheme, Select}; -pub fn select_option(options: &[&str]) -> Option<usize> { +pub fn select_option(prompt: &str, options: &[&str]) -> Option<usize> { let selection = Select::with_theme(&ColorfulTheme::default()) - .with_prompt("Select an option:") + .with_prompt(prompt) .default(0) .items(options) .interact_opt()

@@ -16,9 +16,9 @@

return selection; } -pub fn select_option_string_vec(options: &Vec<String>) -> Option<usize> { +pub fn select_option_string_vec(prompt: &str, options: &Vec<String>) -> Option<usize> { let selection = Select::with_theme(&ColorfulTheme::default()) - .with_prompt("Select an option:") + .with_prompt(prompt) .default(0) .items(&options) .interact_opt()