removed unused warning
This commit is contained in:
parent
d097c41192
commit
7203a7309d
90
src/repo.rs
90
src/repo.rs
@ -2,24 +2,24 @@ use std::fmt;
|
|||||||
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
use crate::common;
|
// use crate::common;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
Conversion,
|
// Conversion,
|
||||||
Empty,
|
// Empty,
|
||||||
NoTagFound,
|
NoTagFound,
|
||||||
InvalidChar,
|
// InvalidChar,
|
||||||
MisformedInput,
|
MisformedInput,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Error::Conversion => write!(f, "Conversion error"),
|
// Error::Conversion => write!(f, "Conversion error"),
|
||||||
Error::Empty => write!(f, "Input is empty"),
|
// Error::Empty => write!(f, "Input is empty"),
|
||||||
Error::NoTagFound => write!(f, "Expected a tag"),
|
Error::NoTagFound => write!(f, "Expected a tag"),
|
||||||
Error::InvalidChar => write!(f, "Invalid character found"),
|
// Error::InvalidChar => write!(f, "Invalid character found"),
|
||||||
Error::MisformedInput => write!(f, "Unexpected input"),
|
Error::MisformedInput => write!(f, "Unexpected input"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -67,13 +67,13 @@ pub fn split_tag_from_repo(input: &str) -> Result<(&str, &str), Error> {
|
|||||||
Ok((front, back))
|
Ok((front, back))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn split_repo(repo: &str) -> Result<Repo, Error> {
|
// pub fn split_repo(repo: &str) -> Result<Repo, Error> {
|
||||||
let split_tag: Vec<&str> = repo.split(":").collect();
|
// let split_tag: Vec<&str> = repo.split(":").collect();
|
||||||
if split_tag.len() == 2 && split_tag[0].len() != 0 && split_tag[1].len() != 0 {
|
// if split_tag.len() == 2 && split_tag[0].len() != 0 && split_tag[1].len() != 0 {
|
||||||
//
|
// //
|
||||||
}
|
// }
|
||||||
Ok(Repo::Project("".into()))
|
// Ok(Repo::Project("".into()))
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub fn split_repo_without_tag(repo: &str) -> Result<Repo, Error> {
|
pub fn split_repo_without_tag(repo: &str) -> Result<Repo, Error> {
|
||||||
let repo = repo.trim();
|
let repo = repo.trim();
|
||||||
@ -117,26 +117,26 @@ pub fn split_tag(repo: &str) -> Result<(&str, &str), Error> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn extract(repo: &str) -> Result<(Option<&str>, Option<&str>, &str), Error> {
|
// pub fn extract(repo: &str) -> Result<(Option<&str>, Option<&str>, &str), Error> {
|
||||||
if repo.len() == 0 {
|
// if repo.len() == 0 {
|
||||||
return Err(Error::Empty);
|
// return Err(Error::Empty);
|
||||||
}
|
// }
|
||||||
let regex = regex::Regex::new(r"([^/:]*?/)??([^/:]*?/)?([^/:]*):?(.*)?").unwrap();
|
// let regex = regex::Regex::new(r"([^/:]*?/)??([^/:]*?/)?([^/:]*):?(.*)?").unwrap();
|
||||||
let caps = match regex.captures(repo) {
|
// let caps = match regex.captures(repo) {
|
||||||
None => return Err(Error::Conversion),
|
// None => return Err(Error::Conversion),
|
||||||
Some(cap) => cap,
|
// Some(cap) => cap,
|
||||||
};
|
// };
|
||||||
let server = match caps.get(1) {
|
// let server = match caps.get(1) {
|
||||||
None => None,
|
// None => None,
|
||||||
Some(cap) => Some(common::remove_last_char(cap.as_str())),
|
// Some(cap) => Some(common::remove_last_char(cap.as_str())),
|
||||||
};
|
// };
|
||||||
let orga = match caps.get(2) {
|
// let orga = match caps.get(2) {
|
||||||
None => None,
|
// None => None,
|
||||||
Some(cap) => Some(common::remove_last_char(cap.as_str())),
|
// Some(cap) => Some(common::remove_last_char(cap.as_str())),
|
||||||
};
|
// };
|
||||||
|
|
||||||
Ok((server, orga, caps.get(3).unwrap().as_str()))
|
// Ok((server, orga, caps.get(3).unwrap().as_str()))
|
||||||
}
|
// }
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
@ -144,18 +144,18 @@ mod tests {
|
|||||||
use crate::repo::{Error, Repo};
|
use crate::repo::{Error, Repo};
|
||||||
|
|
||||||
// #[test]
|
// #[test]
|
||||||
fn test_repo_regex() {
|
// fn test_repo_regex() {
|
||||||
assert_eq!(repo::extract(""), Err(repo::Error::Empty));
|
// assert_eq!(repo::extract(""), Err(repo::Error::Empty));
|
||||||
assert_eq!(
|
// assert_eq!(
|
||||||
repo::extract("ghcr.io/library/nginx"),
|
// repo::extract("ghcr.io/library/nginx"),
|
||||||
Ok((Some("ghcr.io"), Some("library"), "nginx"))
|
// Ok((Some("ghcr.io"), Some("library"), "nginx"))
|
||||||
);
|
// );
|
||||||
assert_eq!(
|
// assert_eq!(
|
||||||
repo::extract("library/nginx"),
|
// repo::extract("library/nginx"),
|
||||||
Ok((None, Some("library"), "nginx"))
|
// Ok((None, Some("library"), "nginx"))
|
||||||
);
|
// );
|
||||||
assert_eq!(repo::extract("nginx"), Ok((None, None, "nginx")));
|
// assert_eq!(repo::extract("nginx"), Ok((None, None, "nginx")));
|
||||||
}
|
// }
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn split_tag() {
|
fn split_tag() {
|
||||||
|
Loading…
Reference in New Issue
Block a user