Implement from_json
This commit is contained in:
parent
d898696d6c
commit
ca4fd34bc1
@ -184,7 +184,13 @@ impl Tool {
|
||||
Tool::Zsh => todo!(),
|
||||
Tool::FromCsv => todo!(),
|
||||
Tool::ToCsv => todo!(),
|
||||
Tool::FromJson => todo!(),
|
||||
Tool::FromJson => {
|
||||
Error::expect_tool_argument_amount("from_json", 1, values.len())?;
|
||||
|
||||
let json_string = values[0].as_string()?;
|
||||
|
||||
serde_json::from_str(json_string)?
|
||||
}
|
||||
Tool::ToJson => todo!(),
|
||||
};
|
||||
|
||||
|
18
src/error.rs
18
src/error.rs
@ -122,6 +122,24 @@ pub enum Error {
|
||||
CustomMessage(String),
|
||||
}
|
||||
|
||||
impl Error {
|
||||
pub fn expect_tool_argument_amount(
|
||||
tool_name: &'static str,
|
||||
expected: usize,
|
||||
actual: usize,
|
||||
) -> Result<()> {
|
||||
if expected == actual {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Error::ExpectedToolArgumentAmount {
|
||||
tool_name,
|
||||
expected,
|
||||
actual,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<csv::Error> for Error {
|
||||
fn from(value: csv::Error) -> Self {
|
||||
Error::ToolFailure(value.to_string())
|
||||
|
Loading…
Reference in New Issue
Block a user