Skip to content

Commit

Permalink
refactor: Add Url & Domain structs
Browse files Browse the repository at this point in the history
  • Loading branch information
sgoudham committed Jun 12, 2022
1 parent 8f7210a commit 34cb2b6
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/git.rs
@@ -1,3 +1,4 @@
use core::fmt;
use mockall::automock;
use std::process::{Command, Output};

Expand All @@ -12,6 +13,19 @@ pub(crate) enum Git<'a> {
IsValidRemote(&'a str),
}

#[derive(Debug)]
pub(crate) enum Domain {
Github(String),
BitBucket(String),
}

#[derive(Debug)]
pub(crate) struct Url {
pub(crate) protocol: String,
pub(crate) domain: Domain,
pub(crate) path: String,
}

pub(crate) enum GitOutput {
Ok(String),
Err(String),
Expand Down Expand Up @@ -79,3 +93,37 @@ impl<'a> GitCommand for Git<'a> {
}
}
}

impl Url {
pub(crate) fn new(protocol: &str, domain: Domain, path: &str) -> Self {
Self {
protocol: protocol.to_owned(),
domain,
path: path.to_owned(),
}
}
}

impl Domain {
pub(crate) fn from_str(s: &str) -> Self {
if s == "bitbucket.org" {
Domain::BitBucket(s.to_owned())
} else {
Domain::Github(s.to_owned())
}
}
}

impl PartialEq for Domain {
fn eq(&self, other: &Self) -> bool {
self.to_string() == other.to_string()
}
}

impl fmt::Display for Domain {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Domain::Github(str) | Domain::BitBucket(str) => write!(f, "{}", str),
}
}
}

0 comments on commit 34cb2b6

Please sign in to comment.