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: Added Json type #203

Merged
merged 1 commit into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/types/json.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use serde_json::Value;

#[derive(Debug, Clone)]
pub struct Json(pub Value);

impl From<Json> for Value {
fn from(item: Json) -> Self {
item.0
}
}

impl std::fmt::Display for Json {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.0.fmt(f)
}
}

impl std::str::FromStr for Json {
type Err = color_eyre::eyre::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let json: Value = serde_json::from_str(s).map_err(color_eyre::eyre::Report::msg)?;
Ok(Self(json))
}
}

impl interactive_clap::ToCli for Json {
type CliVariant = Json;
}
1 change: 1 addition & 0 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod account_id;
pub mod api_key;
pub mod crypto_hash;
pub mod json;
pub mod path_buf;
pub mod public_key;
pub mod secret_key;
Expand Down