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 <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
Fintan Halpenny 2024-06-20 17:21:18 +02:00 committed by cloudhead
parent 42ffbf3fe6
commit 80f1e6516c
No known key found for this signature in database
4 changed files with 15 additions and 17 deletions

View File

@ -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"] ✗ Error: `--allow` and `--disallow` must not overlap: ["did:key:z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk"]
``` ```
Allowing or disallowing the same peer twice will result in an error the second Allowing or disallowing the same peer twice will result in a message saying that
call, since there is no update specified: the document is already up to date:
``` ```
$ rad id update --title "Allow Bob" --allow did:key:z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk -q $ rad id update --title "Allow Bob" --allow did:key:z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk -q
... ...
``` ```
``` (fails) ```
$ rad id update --title "Allow Bob" --allow did:key:z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk -q $ rad id update --title "Allow Bob" --allow did:key:z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk
✗ Error: no update specified Nothing to do. The document is up to date. See `rad inspect --identity`.
✗ Hint: an update to the identity must be specified, run `rad id update -h` to see the available options
``` ```
If we attempt to change the list while also changing the repository to `public`, If we attempt to change the list while also changing the repository to `public`,

View File

@ -74,5 +74,5 @@ Note that we cannot delete mandatory fields:
``` (fails) ``` (fails)
$ rad id update --title "Delete default branch" --payload xyz.radicle.project defaultBranch null $ 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`
``` ```

View File

@ -174,10 +174,9 @@ $ rad id accept 0ca42d376bd566631083c8913cf86bec722da392
✗ Error: [..] ✗ 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`" $ rad id update --title "Update canonical branch" --description "Update the canonical branch to `main`"
✗ Error: no update specified Nothing to do. The document is up to date. See `rad inspect --identity`.
✗ Hint: an update to the identity must be specified, run `rad id update -h` to see the available options
``` ```

View File

@ -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 // Verify that the project payload can still be parsed into the
// `Project` type. // `Project` type.
if let Err(e) = proposal.project() { 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 proposal
}; };
if proposal == current.doc { if proposal == current.doc {
return Err(Error::WithHint { term::print(term::format::italic(
err: anyhow!("no update specified"), "Nothing to do. The document is up to date. See `rad inspect --identity`.",
hint: "an update to the identity must be specified, run `rad id update -h` to see the available options" ));
}.into()); return Ok(());
} }
let revision = update(title, description, proposal, &mut identity, &signer)?; let revision = update(title, description, proposal, &mut identity, &signer)?;