Skip to content

Commit

Permalink
feat: code structure
Browse files Browse the repository at this point in the history
  • Loading branch information
rootCircle committed Jun 22, 2024
1 parent 4bb574f commit ff7a9b5
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/cmd/check.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub(crate) fn check() {
println!("Here is log!");
}
println!("Here is check!");
}
2 changes: 1 addition & 1 deletion src/cmd/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ pub(crate) fn default_cmd_workflow() {
println!(" {}", multiselected[selection]);
}
}
}
}
4 changes: 2 additions & 2 deletions src/cmd/init.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub(crate) fn init() {
println!("Here is log!");
}
println!("Here is init!");
}
34 changes: 33 additions & 1 deletion src/events.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::rules::BgitRule;
mod git_add;
mod git_branch;
mod git_checkout;
Expand All @@ -9,4 +10,35 @@ mod git_init;
mod git_pull;
mod git_push;
mod git_restore;
mod git_status;
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 <event name> {
/// 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<GitEvent>;
fn get_rules(&self) -> Vec<Box<dyn BgitRule>>;
fn apply(&self) -> Result<bool, &str>;
}
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(unused, dead_code)]
use std::process::exit;
use crate::cmd::{BgitCli, Commands};
use crate::cmd::_clone_url::clone;
Expand Down
26 changes: 26 additions & 0 deletions src/rules.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::events::BgitEvent;

mod a11_git_remote_http_ssh;
mod a03_github_username;
mod a09_commit_gpg_sign;
Expand All @@ -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<Box<dyn BgitEvent>>) -> Self where Self: Sized;
fn get_name(&self) -> String;
fn get_id(&self) -> u32;
fn get_level(&self) -> BgitRuleLevel;
fn get_event(&self) -> Vec<Box<dyn BgitEvent>>;
fn check(&self) -> Result<BgitRuleOutput, String>;
fn apply(&self) -> Result<bool, &str>;
fn verify(&self) -> Result<bool, &str>;
}

9 changes: 8 additions & 1 deletion src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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<Option<Box<dyn BgitTask>>, &str>;
}

0 comments on commit ff7a9b5

Please sign in to comment.