feat: added command functionality to install
All checks were successful
/ check (push) Successful in 39s

This commit is contained in:
Didier Slof 2023-07-17 17:47:42 +02:00
parent 1a95046b87
commit d9d4728dd6
Signed by: didier
GPG key ID: 01E71F18AA4398E5
20 changed files with 464 additions and 76 deletions

View file

@ -26,6 +26,7 @@ impl Error for PackageIdentifierError {}
pub enum PackageIdentifier {
PackageLocator(PackageLocator),
URI(String),
Path(String),
}
impl std::fmt::Display for PackageIdentifier {
@ -33,6 +34,7 @@ impl std::fmt::Display for PackageIdentifier {
match self {
PackageIdentifier::PackageLocator(pl) => write!(f, "{}", pl),
PackageIdentifier::URI(uri) => write!(f, "{}", uri),
PackageIdentifier::Path(path) => write!(f, "{}", path),
}
}
}
@ -61,7 +63,7 @@ impl FromStr for PackageIdentifier {
type Err = PackageIdentifierError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let uri_re = regex::Regex::new(r"^[a-zA-Z0-9]+://").unwrap();
let uri_re = Regex::new(r"^[a-zA-Z0-9]+://").unwrap();
if uri_re.is_match(s) {
// there needs to be stuff after the protocol
let split = s.split("://").collect::<Vec<&str>>();
@ -69,6 +71,8 @@ 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() {
return Ok(PackageIdentifier::Path(s.to_string()));
} else {
let pl = match PackageLocator::from_str(s) {
Ok(pl) => pl,
@ -84,7 +88,7 @@ impl FromStr for PackageLocator {
fn from_str(s: &str) -> Result<Self, Self::Err> {
#[allow(unused_assignments)] // false positive
let mut name = None;
let mut name = None;
let mut version = None;
let mut tags = None;