-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 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
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; | ||
} |
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