Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): Restore packages from webcs #5089

Merged
14 changes: 14 additions & 0 deletions lib/config/src/package/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ pub struct Package {
}

impl Package {
pub fn new_empty() -> Self {
PackageBuilder::default().build().unwrap()
}

/// Create a [`PackageBuilder`] populated with all mandatory fields.
pub fn builder(
name: impl Into<String>,
Expand Down Expand Up @@ -732,6 +736,16 @@ pub struct Manifest {
}

impl Manifest {
pub fn new_empty() -> Self {
Self {
package: None,
dependencies: HashMap::new(),
fs: IndexMap::new(),
modules: Vec::new(),
commands: Vec::new(),
}
}

/// Create a [`ManifestBuilder`] populated with all mandatory fields.
pub fn builder(package: Package) -> ManifestBuilder {
ManifestBuilder::new(package)
Expand Down
39 changes: 39 additions & 0 deletions lib/package/src/convert/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use std::sync::Arc;

#[derive(Clone, Debug)]
pub struct ManifestConversionError {
message: String,
cause: Option<Arc<dyn std::error::Error + Send + Sync>>,
}

impl ManifestConversionError {
pub fn msg(msg: impl Into<String>) -> Self {
Self {
message: msg.into(),
cause: None,
}
}

pub fn with_cause(
msg: impl Into<String>,
cause: impl std::error::Error + Send + Sync + 'static,
) -> Self {
Self {
message: msg.into(),
cause: Some(Arc::new(cause)),
}
}
}

impl std::fmt::Display for ManifestConversionError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "could not convert manifest: {}", self.message)?;
if let Some(cause) = &self.cause {
write!(f, " (cause: {})", cause)?;
}

Ok(())
}
}

impl std::error::Error for ManifestConversionError {}
4 changes: 4 additions & 0 deletions lib/package/src/convert/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mod error;
mod webc_to_package;

pub use self::{error::ManifestConversionError, webc_to_package::webc_to_package_dir};
Loading