From 80f1e6516cfb2412988c72deb3dd024c2a920bf3 Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Thu, 20 Jun 2024 17:21:18 +0200 Subject: [PATCH] cli: idempotent `rad id update` Instead of producing an error when there is no update during `rad id update`, a message that the document is up to date is printed. The command is considered is considered successful. Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- radicle-cli/examples/rad-id-private.md | 11 +++++------ radicle-cli/examples/rad-id-update-delete-field.md | 2 +- radicle-cli/examples/rad-id.md | 9 ++++----- radicle-cli/src/commands/id.rs | 10 +++++----- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/radicle-cli/examples/rad-id-private.md b/radicle-cli/examples/rad-id-private.md index 05262694..63998838 100644 --- a/radicle-cli/examples/rad-id-private.md +++ b/radicle-cli/examples/rad-id-private.md @@ -62,17 +62,16 @@ $ rad id update --title "Remove allow list" --allow did:key:z6Mkt67GdsW7715MEfRu ✗ Error: `--allow` and `--disallow` must not overlap: ["did:key:z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk"] ``` -Allowing or disallowing the same peer twice will result in an error the second -call, since there is no update specified: +Allowing or disallowing the same peer twice will result in a message saying that +the document is already up to date: ``` $ rad id update --title "Allow Bob" --allow did:key:z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk -q ... ``` -``` (fails) -$ rad id update --title "Allow Bob" --allow did:key:z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk -q -✗ Error: no update specified -✗ Hint: an update to the identity must be specified, run `rad id update -h` to see the available options +``` +$ rad id update --title "Allow Bob" --allow did:key:z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk +Nothing to do. The document is up to date. See `rad inspect --identity`. ``` If we attempt to change the list while also changing the repository to `public`, diff --git a/radicle-cli/examples/rad-id-update-delete-field.md b/radicle-cli/examples/rad-id-update-delete-field.md index b34cbd4b..7f80573c 100644 --- a/radicle-cli/examples/rad-id-update-delete-field.md +++ b/radicle-cli/examples/rad-id-update-delete-field.md @@ -74,5 +74,5 @@ Note that we cannot delete mandatory fields: ``` (fails) $ rad id update --title "Delete default branch" --payload xyz.radicle.project defaultBranch null -✗ Error: failed to verify `xyz.radicle.project`, failed with json: missing field `defaultBranch` +✗ Error: failed to verify `xyz.radicle.project`, json: missing field `defaultBranch` ``` diff --git a/radicle-cli/examples/rad-id.md b/radicle-cli/examples/rad-id.md index 259c8456..2bc93ed8 100644 --- a/radicle-cli/examples/rad-id.md +++ b/radicle-cli/examples/rad-id.md @@ -174,10 +174,9 @@ $ rad id accept 0ca42d376bd566631083c8913cf86bec722da392 ✗ Error: [..] ``` -If no updates are specified then the update will fail: +If no updates are specified then we are told that our command had no effect: -``` (fail) -$ rad id update --title "Update canonical branch" --description "Update the canonical branch to `main`" -✗ Error: no update specified -✗ Hint: an update to the identity must be specified, run `rad id update -h` to see the available options +``` +$ rad id update --title "Update canonical branch" --description "Update the canonical branch to `main`" +Nothing to do. The document is up to date. See `rad inspect --identity`. ``` diff --git a/radicle-cli/src/commands/id.rs b/radicle-cli/src/commands/id.rs index 2e5a5d2e..fe8b358b 100644 --- a/radicle-cli/src/commands/id.rs +++ b/radicle-cli/src/commands/id.rs @@ -465,15 +465,15 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { // Verify that the project payload can still be parsed into the // `Project` type. if let Err(e) = proposal.project() { - anyhow::bail!("failed to verify `xyz.radicle.project`, failed with {e}",); + anyhow::bail!("failed to verify `xyz.radicle.project`, {e}"); } proposal }; if proposal == current.doc { - return Err(Error::WithHint { - err: anyhow!("no update specified"), - hint: "an update to the identity must be specified, run `rad id update -h` to see the available options" - }.into()); + term::print(term::format::italic( + "Nothing to do. The document is up to date. See `rad inspect --identity`.", + )); + return Ok(()); } let revision = update(title, description, proposal, &mut identity, &signer)?;