Skip to content

Commit

Permalink
chore(refactor): refactored all unused code out
Browse files Browse the repository at this point in the history
  • Loading branch information
veritem committed Dec 18, 2023
1 parent 591c1a4 commit c044bee
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 119 deletions.
132 changes: 83 additions & 49 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ keywords = ["git", "commit", "conventional", "commits"]

[dependencies]
clap = { version = "4.0", features = ["derive"] }
console = "0.15.7"
dialoguer = "0.11.0"
inquire = "0.6.2"
serde = {version = "1.0.188", features = ["derive"]}
serde_yaml = "0.9.25"
yaml-rust = "0.4.5"
yaml-rust = "0.4.5"
82 changes: 33 additions & 49 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,64 +1,35 @@
use std::collections::HashMap;

use crate::utils::GCommitConfig;
use dialoguer::{theme::ColorfulTheme, Input, Select};
use std::collections::HashMap;

pub fn new_commit(config: &GCommitConfig) -> String {
let comm_type = commit_type(config.classes.clone());

let empty_scope = String::from("");

let comm_scope = match commit_scope() {
Some(scope) => match config.scopes.contains(&scope) {
true => scope,
false => scope,
},
None => empty_scope,
};

let commit_type = commit_type(config.classes.clone());
let commit_scope = get_commit_scope();
let comm_desc = commit_description();
let comm_body = commit_body();

let mut commit = comm_type;
let mut commit = String::from(format!("{commit_type}({commit_scope}): {comm_desc}"));

if comm_scope.len() > 2 {
commit.push_str(&format!("({comm_scope})"))
if commit_scope.trim().is_empty() {
commit = String::from(format!("{commit_type}: {comm_desc}"));
}
commit.push_str(&format!(": {comm_desc}"));

if comm_body.len() > 2 {
if !comm_body.trim().is_empty() {
commit.push_str(&format!("\n\n{comm_body}"));
}
commit
}
fn commit_type(classes: HashMap<String, String>) -> String {
let mut options: Vec<String> = vec![];
let mut classes_with_desc: Vec<String> = vec![];
for (k, v) in classes {
let formatted_string = format!("{}\t\t{}", k, v);
classes_with_desc.push(formatted_string);
options.push(k);
}

let selection = match Select::with_theme(&ColorfulTheme::default())
.with_prompt("Select type of commit")
.default(0)
.items(&classes_with_desc)
.interact_opt()
.unwrap()
{
Some(val) => &options[val],
None => &options[0],
};
selection.to_string()
commit
}

fn commit_scope() -> Option<String> {
let input: String = Input::with_theme(&ColorfulTheme::default())
fn get_commit_scope() -> String {
let commit_scope = Input::with_theme(&ColorfulTheme::default())
.with_prompt("scope (optional)")
.allow_empty(true)
.interact_text()
.unwrap();
Some(input)

commit_scope
}

fn commit_description() -> String {
Expand All @@ -81,11 +52,24 @@ fn commit_body() -> String {
input
}

fn _commit_footer() -> String {
let input: String = Input::with_theme(&ColorfulTheme::default())
.with_prompt("footer")
.allow_empty(true)
.interact_text()
.unwrap();
input
fn commit_type(classes: HashMap<String, String>) -> String {
let mut options: Vec<String> = vec![];
let mut classes_with_desc: Vec<String> = vec![];
for (k, v) in classes {
let formatted_string = format!("{}\t\t{}", k, v);
classes_with_desc.push(formatted_string);
options.push(k);
}

let selection = match Select::with_theme(&ColorfulTheme::default())
.with_prompt("Select type of commit")
.default(0)
.items(&classes_with_desc)
.interact_opt()
.unwrap()
{
Some(val) => &options[val],
None => &options[0],
};
selection.to_string()
}

0 comments on commit c044bee

Please sign in to comment.