From ff7a9b546891852208c01596a0d10ba387a6eddc Mon Sep 17 00:00:00 2001 From: Lab Rat Date: Sat, 22 Jun 2024 23:40:12 +0530 Subject: [PATCH] feat: code structure --- src/cmd/check.rs | 4 ++-- src/cmd/default.rs | 2 +- src/cmd/init.rs | 4 ++-- src/events.rs | 34 +++++++++++++++++++++++++++++++++- src/main.rs | 1 + src/rules.rs | 26 ++++++++++++++++++++++++++ src/tasks.rs | 9 ++++++++- 7 files changed, 73 insertions(+), 7 deletions(-) diff --git a/src/cmd/check.rs b/src/cmd/check.rs index b7e14da..ce35fdf 100644 --- a/src/cmd/check.rs +++ b/src/cmd/check.rs @@ -1,3 +1,3 @@ pub(crate) fn check() { - println!("Here is log!"); -} \ No newline at end of file + println!("Here is check!"); +} diff --git a/src/cmd/default.rs b/src/cmd/default.rs index 527c699..647f65a 100644 --- a/src/cmd/default.rs +++ b/src/cmd/default.rs @@ -23,4 +23,4 @@ pub(crate) fn default_cmd_workflow() { println!(" {}", multiselected[selection]); } } -} \ No newline at end of file +} diff --git a/src/cmd/init.rs b/src/cmd/init.rs index 2d204df..16552b0 100644 --- a/src/cmd/init.rs +++ b/src/cmd/init.rs @@ -1,3 +1,3 @@ pub(crate) fn init() { - println!("Here is log!"); -} \ No newline at end of file + println!("Here is init!"); +} diff --git a/src/events.rs b/src/events.rs index 896e406..1b8a966 100644 --- a/src/events.rs +++ b/src/events.rs @@ -1,3 +1,4 @@ +use crate::rules::BgitRule; mod git_add; mod git_branch; mod git_checkout; @@ -9,4 +10,35 @@ mod git_init; mod git_pull; mod git_push; mod git_restore; -mod git_status; \ No newline at end of file +mod git_status; + +/// List of various Git Events to be called with git2-rs library +pub enum GitEvent { + Init, + Add, + Commit, + Push, + Pull, + Rebase, + Merge, + Log, + Status +} +/// Sample schema for an Events +/// ```rs +/// struct { +/// name: String, +/// action_description: String, +/// id: u32, +/// args: Vec<> +/// } +/// ``` +pub(crate) trait BgitEvent { + fn new(name: String, action_description: String, id: u32, args: Vec<&str>) -> Self where Self: Sized; + fn get_name(&self) -> String; + fn get_action_description(&self) -> String; + fn get_id(&self) -> u32; + fn get_type(&self) -> Vec; + fn get_rules(&self) -> Vec>; + fn apply(&self) -> Result; +} diff --git a/src/main.rs b/src/main.rs index 96e7720..8147541 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +#[allow(unused, dead_code)] use std::process::exit; use crate::cmd::{BgitCli, Commands}; use crate::cmd::_clone_url::clone; diff --git a/src/rules.rs b/src/rules.rs index 153258d..1c38be3 100644 --- a/src/rules.rs +++ b/src/rules.rs @@ -1,3 +1,5 @@ +use crate::events::BgitEvent; + mod a11_git_remote_http_ssh; mod a03_github_username; mod a09_commit_gpg_sign; @@ -12,3 +14,27 @@ mod a12_no_secrets_staged; mod a13_git_lfs; mod a14_big_repo_size; mod a15_file_not_gitignored; + +pub enum BgitRuleLevel { + Allow, + Warning, + Error +} + +pub enum BgitRuleOutput { + Allowed, + Warning(String), + Fine +} + +pub trait BgitRule { + fn new(name: String, id: u32, level: BgitRuleLevel, events: Vec>) -> Self where Self: Sized; + fn get_name(&self) -> String; + fn get_id(&self) -> u32; + fn get_level(&self) -> BgitRuleLevel; + fn get_event(&self) -> Vec>; + fn check(&self) -> Result; + fn apply(&self) -> Result; + fn verify(&self) -> Result; +} + diff --git a/src/tasks.rs b/src/tasks.rs index 89f07b7..7dcede1 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -7,4 +7,11 @@ mod ta06_do_pop_stash; mod ta07_has_unstaged_files; mod ta08_ask_to_stage_file; mod ta09_ask_to_stage_file_all_file; -mod ta10_ask_to_stage_file_discretely_add; \ No newline at end of file +mod ta10_ask_to_stage_file_discretely_add; + +pub trait BgitTask { + fn new(name: String, id: u32) -> Self where Self: Sized; + fn get_name(&self) -> String; + fn get_id(&self) -> u32; + fn apply_task(&self) -> Result>, &str>; +}