-
Notifications
You must be signed in to change notification settings - Fork 44
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
[restatectl] Support metadata Put #2055
Conversation
This commit adds support for put operations for metadata It is just a convenience around patch.
@igalshilman take a look at clap_stdin to allow reading the input from stdin rather than with e.g.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this will do the trick! Thank you for helping out, @igalshilman!
if let Some(obj) = doc.as_object_mut() { | ||
// make sure that the value does not contain the version field. | ||
obj.remove("version"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine, since patch will insert its own version, derived from the store-read version, on the write path.
@AhmedSoliman ha nice, i didn't know about that. |
it'd be a file path or through stdin, for instance
or
or
So it replaces |
b44624c
to
fe92a6d
Compare
use crate::commands::metadata::patch::{patch_value, PatchValueOpts}; | ||
use crate::commands::metadata::MetadataCommonOpts; | ||
use anyhow::anyhow; | ||
use clap::Parser; | ||
use clap_stdin::FileOrStdin; | ||
use cling::{Collect, Run}; | ||
use serde_json::Value; | ||
use std::collections::HashMap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Our convention is to split imports into
<std>
blank
<third-party>
blank
<restate_*>
blank
<crate/super/self::*>
let mut doc: Value = serde_json::from_str(&doc_body) | ||
.map_err(|e| anyhow::anyhow!("Parsing JSON value: {}", e))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let mut doc: Value = serde_json::from_str(&doc_body) | |
.map_err(|e| anyhow::anyhow!("Parsing JSON value: {}", e))?; | |
let mut doc: Value = serde_json::from_str(&doc_body).context("Failed to parse JSON value")?; |
Although I don't think we need either solutions.
patch_command.insert("value", doc); | ||
|
||
let patch = vec![patch_command]; | ||
let patch_as_str = serde_json::to_string_pretty(&patch).map_err(|e| anyhow::anyhow!(e))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't need to map_err in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
Thanks for the review @AhmedSoliman and @pcholakov, |
This commit adds support for put operations for metadata It is just a convenience around patch.
Either:
Or: