feat: multiline logging
All checks were successful
/ check (push) Successful in 38s

This commit is contained in:
Didier Slof 2023-07-19 16:15:26 +02:00
parent b115b91ecb
commit e4eb85f535
Signed by: didier
GPG key ID: 01E71F18AA4398E5
7 changed files with 75 additions and 38 deletions

View file

@ -7,15 +7,15 @@ use regex::Regex;
pub enum PackageIdentifierError {
InvalidPackageLocator(String),
InvalidURI(String),
InvalidPath(String),
}
impl std::fmt::Display for PackageIdentifierError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
PackageIdentifierError::InvalidPackageLocator(s) => {
write!(f, "Invalid package locator: {}", s)
}
PackageIdentifierError::InvalidPackageLocator(s) => write!(f, "Invalid package locator: {}", s),
PackageIdentifierError::InvalidURI(s) => write!(f, "Invalid URI: {}", s),
PackageIdentifierError::InvalidPath(s) => write!(f, "Invalid path: {}", s),
}
}
}
@ -71,7 +71,18 @@ impl FromStr for PackageIdentifier {
return Err(PackageIdentifierError::InvalidURI(s.to_string()));
}
Ok(PackageIdentifier::URI(s.to_string()))
} else if std::path::Path::new(s).exists() {
} else if s.starts_with("/")
|| s.starts_with("./")
|| s.starts_with("../")
|| s.starts_with("~/")
{
let path = std::path::Path::new(s);
if s.ends_with("/")
|| !path.exists()
|| path.is_dir()
{
return Err(PackageIdentifierError::InvalidPath(s.to_string()));
}
return Ok(PackageIdentifier::Path(s.to_string()));
} else {
let pl = match PackageLocator::from_str(s) {