fix(frontmatter): value parsing to corret yaml value type
This commit is contained in:
21
src/main.rs
21
src/main.rs
@@ -37,7 +37,7 @@ enum FrontmatterCommands {
|
|||||||
property: String,
|
property: String,
|
||||||
|
|
||||||
#[clap()]
|
#[clap()]
|
||||||
value: serde_yaml::Value,
|
value: String,
|
||||||
},
|
},
|
||||||
Remove {
|
Remove {
|
||||||
#[clap()]
|
#[clap()]
|
||||||
@@ -129,9 +129,22 @@ fn main() {
|
|||||||
match Frontmatter::try_from(ast) {
|
match Frontmatter::try_from(ast) {
|
||||||
Ok(mut frontmatter) => match command {
|
Ok(mut frontmatter) => match command {
|
||||||
FrontmatterCommands::Set { property, value } => {
|
FrontmatterCommands::Set { property, value } => {
|
||||||
frontmatter.insert(String::from(property), value.to_owned());
|
match serde_yaml::from_str(&value) {
|
||||||
frontmatter.insert_ast(ast);
|
Ok(value) => {
|
||||||
cli::ResultType::Markdown(ast)
|
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 } => {
|
FrontmatterCommands::Remove { property } => {
|
||||||
let _ = frontmatter.remove(String::from(property));
|
let _ = frontmatter.remove(String::from(property));
|
||||||
|
|||||||
Reference in New Issue
Block a user