From 39fa46b644c5049e1fdd68fefdbac2cd06dca768 Mon Sep 17 00:00:00 2001 From: "Gustavo \"Guz\" L. de Mello" Date: Wed, 1 May 2024 10:04:26 -0300 Subject: [PATCH] fix(frontmatter): value parsing to corret yaml value type --- src/main.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index cee4884..672152a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,7 +37,7 @@ enum FrontmatterCommands { property: String, #[clap()] - value: serde_yaml::Value, + value: String, }, Remove { #[clap()] @@ -129,9 +129,22 @@ fn main() { match Frontmatter::try_from(ast) { Ok(mut frontmatter) => match command { FrontmatterCommands::Set { property, value } => { - frontmatter.insert(String::from(property), value.to_owned()); - frontmatter.insert_ast(ast); - cli::ResultType::Markdown(ast) + match serde_yaml::from_str(&value) { + Ok(value) => { + frontmatter.insert(String::from(property), value); + frontmatter.insert_ast(ast); + cli::ResultType::Markdown(ast) + } + Err(err) => cli::ResultType::Err(cli::Error { + code: cli::ErrorCode::EPRSG, + description: format!( + "Error parsing value to Yaml calue:\n{:#?}", + err + ), + fix: None, + url: None, + }), + } } FrontmatterCommands::Remove { property } => { let _ = frontmatter.remove(String::from(property));