aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md5
-rw-r--r--docs/guides/federation/writing-and-reading.md7
-rw-r--r--share/bash-completion/completions/continuum-party2
-rw-r--r--src/federation/party.rs44
4 files changed, 51 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 427ae21..e7dda5b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,11 @@ it from the release before ([`docs/operations.md`](docs/operations.md),
## Unreleased
+* `continuum-party write -r` writes the value as a string, as it is, not JSON
+ ([`docs/guides/federation/writing-and-reading.md`](docs/guides/federation/writing-and-reading.md),
+ [Writing](docs/guides/federation/writing-and-reading.md#writing);
+ [`src/federation/party.rs`](src/federation/party.rs)).
+
* `continuum-party status` says everything about the federation at the node but the
values: every party's keys and nodes, when each was heard from and what it runs, every
proposal with its votes, who hasn't voted, and what it does, and the party's own key,
diff --git a/docs/guides/federation/writing-and-reading.md b/docs/guides/federation/writing-and-reading.md
index c6b27ba..a5b7ec3 100644
--- a/docs/guides/federation/writing-and-reading.md
+++ b/docs/guides/federation/writing-and-reading.md
@@ -28,7 +28,12 @@ continuum-party --node http://tv:secret@localhost:3000 --key tv.key --record tv.
The value is any JSON: integers from −2⁵³ to 2⁵³ but no fractions, strings of whole
Unicode characters, objects and arrays nested up to 32 deep with the event's own
-object, the whole event up to 256 KiB. `null` empties the place.
+object, the whole event up to 256 KiB. `null` empties the place. `-r` takes the value as
+a string, as it is, not JSON:
+
+```sh
+continuum-party write -r home/tv/motd 'hello, world'
+```
The client signs the write with its key (`--key`), on the heads its node shows, which
are what the party read; records it (`--record`), to sign it again after a move; and puts
diff --git a/share/bash-completion/completions/continuum-party b/share/bash-completion/completions/continuum-party
index 570aeb1..be1729c 100644
--- a/share/bash-completion/completions/continuum-party
+++ b/share/bash-completion/completions/continuum-party
@@ -221,7 +221,7 @@ _continuum_party()
write | values | get)
if [[ $cur == -* ]]; then
[[ $command == values ]] && _continuum_party_words '--json'
- [[ $command == get ]] && _continuum_party_words '-r --raw'
+ [[ $command == values ]] || _continuum_party_words '-r --raw'
elif ((n == 0)); then
_continuum_party_words "$(_continuum_party_places)"
fi
diff --git a/src/federation/party.rs b/src/federation/party.rs
index e030048..8f5143b 100644
--- a/src/federation/party.rs
+++ b/src/federation/party.rs
@@ -133,7 +133,14 @@ fn command() -> Command {
Command::new("write")
.about("Writes a value (JSON) at a path")
.arg(id("path"))
- .arg(id("value")),
+ .arg(id("value"))
+ .arg(
+ Arg::new("raw")
+ .short('r')
+ .long("raw")
+ .action(ArgAction::SetTrue)
+ .help("The value a string as it is, not JSON"),
+ ),
)
.subcommand(
Command::new("keys")
@@ -914,10 +921,9 @@ pub(crate) async fn main() -> Result<()> {
match (name, sub) {
("write", sub) => {
let path_to = sub.get_one::<String>("path").expect("required");
- let value: JsonValue =
- serde_json::from_str(sub.get_one::<String>("value").expect("required"))
- .context("the value isn't JSON")?;
- let value = client::json(&value).map_err(|why| anyhow!(why))?;
+ let given = sub.get_one::<String>("value").expect("required");
+ let value =
+ client::json(&written(given, sub.get_flag("raw"))?).map_err(|why| anyhow!(why))?;
sign(
&node,
&signer,
@@ -1191,6 +1197,14 @@ fn keys_given(given: &[String]) -> Result<Vec<String>> {
}
/// `given`, where each is a node ID.
+/// The value `write` was given: JSON, or with `-r` (`raw`) a string as it is.
+fn written(given: &str, raw: bool) -> Result<JsonValue> {
+ if raw {
+ return Ok(given.into());
+ }
+ serde_json::from_str(given).context("the value isn't JSON; -r writes it as a string")
+}
+
fn node_ids(given: Vec<String>) -> Result<Vec<String>> {
match given.iter().find(|id| !keys::node_id(id)) {
Some(none) => bail!("{none:?} isn't a node ID"),
@@ -2547,6 +2561,26 @@ mod tests {
super::command().debug_assert();
}
+ /// `write` takes JSON, or with `-r` a string as it is, JSON or not.
+ #[test]
+ fn a_value_as_json_or_as_it_is() {
+ use serde_json::json;
+ assert_eq!(
+ super::written(r#"{"a": 1}"#, false).unwrap(),
+ json!({"a": 1})
+ );
+ assert_eq!(super::written(r#""hello""#, false).unwrap(), json!("hello"));
+ assert!(super::written("hello", false).is_err());
+ assert_eq!(
+ super::written("hello, world", true).unwrap(),
+ json!("hello, world")
+ );
+ assert_eq!(
+ super::written(r#"{"a": 1}"#, true).unwrap(),
+ json!(r#"{"a": 1}"#)
+ );
+ }
+
/// `propose` and `fork` take a file, or a subcommand saying what the version is for,
/// with their options after it.
#[test]