-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from lf-lang/librarify
Librarify
- Loading branch information
Showing
15 changed files
with
620 additions
and
242 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use crate::package::tree::GitLock; | ||
use std::io; | ||
|
||
pub mod args; | ||
pub mod backends; | ||
pub mod package; | ||
pub mod util; | ||
|
||
#[derive(Debug)] | ||
pub enum WhichError { | ||
/// An executable binary with that name was not found | ||
CannotFindBinaryPath, | ||
/// There was nowhere to search and the provided name wasn't an absolute path | ||
CannotGetCurrentDirAndPathListEmpty, | ||
/// Failed to canonicalize the path found | ||
CannotCanonicalize, | ||
} | ||
#[derive(Debug)] | ||
pub struct GitCloneError(pub String); // TODO: create a more domain-specific error time like the actual git2::Error | ||
|
||
impl std::fmt::Display for WhichError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
WhichError::CannotFindBinaryPath => write!(f, "cannot find binary"), | ||
WhichError::CannotGetCurrentDirAndPathListEmpty => { | ||
write!(f, "cannot get current dir and path list empty") | ||
} | ||
WhichError::CannotCanonicalize => write!(f, "cannot canonicalize"), | ||
} | ||
} | ||
} | ||
|
||
impl std::fmt::Display for GitCloneError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "{}", self.0) | ||
} | ||
} | ||
|
||
impl std::error::Error for WhichError {} | ||
|
||
impl std::error::Error for GitCloneError {} | ||
|
||
pub struct GitUrl<'a>(&'a str); | ||
|
||
impl<'a> From<&'a str> for GitUrl<'a> { | ||
fn from(value: &'a str) -> Self { | ||
GitUrl(value) | ||
} | ||
} | ||
|
||
impl<'a> From<GitUrl<'a>> for &'a str { | ||
fn from(value: GitUrl<'a>) -> Self { | ||
value.0 | ||
} | ||
} | ||
|
||
pub type WhichCapability<'a> = Box<dyn Fn(&str) -> Result<std::path::PathBuf, WhichError> + 'a>; | ||
pub type GitCloneCapability<'a> = | ||
Box<dyn Fn(GitUrl, &std::path::Path) -> Result<(), GitCloneError> + 'a>; | ||
pub type FsReadCapability<'a> = Box<dyn Fn(&std::path::Path) -> io::Result<String> + 'a>; | ||
pub type GitCloneAndCheckoutCap<'a> = Box< | ||
dyn Fn(GitUrl, &std::path::Path, Option<GitLock>) -> Result<Option<String>, GitCloneError> + 'a, | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.