-
Notifications
You must be signed in to change notification settings - Fork 9
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 #141 from Web3-Builders-Alliance/main
- Loading branch information
Showing
241 changed files
with
8,866 additions
and
2,280 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
[package] | ||
name = "soda-cli" | ||
version = "0.0.5" | ||
version = "0.1.1" | ||
edition = "2021" | ||
license = "Apache-2.0" | ||
description = "Generates Solana Projects from an IDL" | ||
repository = "https://github.com/Web3-Builders-Alliance/soda" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
serde_json = "1.0.93" | ||
clap = { version = "4.1.8", features = ["derive"] } | ||
soda_sol = "0.0.5" | ||
soda_sol = "0.0.6" |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
use std::sync::{MutexGuard, PoisonError}; | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum Error { | ||
#[error("soda_sol crate error: {message}")] | ||
CustomError { message: String }, | ||
} | ||
#[derive(serde::Serialize, serde::Deserialize)] | ||
struct ErrorWrapper { | ||
error: String, | ||
} | ||
impl serde::Serialize for Error { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: serde::ser::Serializer, | ||
{ | ||
let error_message = match self { | ||
Error::CustomError { message } => message, | ||
}; | ||
let wrapper = ErrorWrapper { | ||
error: error_message.to_string(), | ||
}; | ||
wrapper.serialize(serializer) | ||
} | ||
} | ||
|
||
impl<'de> serde::Deserialize<'de> for Error { | ||
fn deserialize<D>(deserializer: D) -> Result<Error, D::Error> | ||
where | ||
D: serde::de::Deserializer<'de>, | ||
{ | ||
let wrapper = ErrorWrapper::deserialize(deserializer)?; | ||
Ok(Error::CustomError { | ||
message: wrapper.error, | ||
}) | ||
} | ||
} | ||
|
||
impl From<bincode::Error> for Error { | ||
fn from(err: bincode::Error) -> Error { | ||
Error::CustomError { | ||
message: err.to_string(), | ||
} | ||
} | ||
} | ||
|
||
impl From<std::io::Error> for Error { | ||
fn from(err: std::io::Error) -> Error { | ||
Error::CustomError { | ||
message: err.to_string(), | ||
} | ||
} | ||
} | ||
|
||
impl From<Result<(), std::io::Error>> for Error { | ||
fn from(err: Result<(), std::io::Error>) -> Error { | ||
match err { | ||
Ok(_) => Error::CustomError { | ||
message: "no error".to_string(), | ||
}, | ||
Err(err) => Error::CustomError { | ||
message: err.to_string(), | ||
}, | ||
} | ||
} | ||
} | ||
|
||
impl From<serde_json::Error> for Error { | ||
fn from(err: serde_json::Error) -> Error { | ||
Error::CustomError { | ||
message: err.to_string(), | ||
} | ||
} | ||
} | ||
|
||
impl From<handlebars::RenderError> for Error { | ||
fn from(err: handlebars::RenderError) -> Error { | ||
Error::CustomError { | ||
message: err.to_string(), | ||
} | ||
} | ||
} | ||
|
||
impl<T> From<PoisonError<MutexGuard<'_, T>>> for Error { | ||
fn from(err: PoisonError<MutexGuard<'_, T>>) -> Error { | ||
Error::CustomError { | ||
message: err.to_string(), | ||
} | ||
} | ||
} |
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,12 @@ | ||
use crate::*; | ||
use std::path::PathBuf; | ||
|
||
pub fn generate_from_idl(base_path: &str, idl: IDL, template_path: &str) -> Result<(), Error> { | ||
let template = if PathBuf::from(template_path).is_file() { | ||
load_template(template_path)? | ||
} else { | ||
get_template_from_fs(template_path)? | ||
}; | ||
let dinamyc_files = generate_project(template, &idl)?; | ||
write_project_to_fs(dinamyc_files, base_path) | ||
} |
Oops, something went wrong.