cli: rad id update --edit
Introduce an `--edit` option to `rad id update` to allow a user to open up their text editor for changing the document's contents.
This commit is contained in:
parent
c6d975799a
commit
43e08a8e70
|
|
@ -5,7 +5,7 @@ use std::{ffi::OsString, io};
|
||||||
use anyhow::{anyhow, Context};
|
use anyhow::{anyhow, Context};
|
||||||
|
|
||||||
use radicle::cob::identity::{self, IdentityMut, Revision, RevisionId};
|
use radicle::cob::identity::{self, IdentityMut, Revision, RevisionId};
|
||||||
use radicle::identity::{doc, Doc, Identity, RawDoc, Visibility};
|
use radicle::identity::{doc, Doc, Identity, PayloadError, RawDoc, Visibility};
|
||||||
use radicle::prelude::{Did, RepoId, Signer};
|
use radicle::prelude::{Did, RepoId, Signer};
|
||||||
use radicle::storage::refs;
|
use radicle::storage::refs;
|
||||||
use radicle::storage::{ReadRepository, ReadStorage as _, WriteRepository};
|
use radicle::storage::{ReadRepository, ReadStorage as _, WriteRepository};
|
||||||
|
|
@ -33,8 +33,7 @@ Usage
|
||||||
[--delegate <did>] [--rescind <did>]
|
[--delegate <did>] [--rescind <did>]
|
||||||
[--threshold <num>] [--visibility <private | public>]
|
[--threshold <num>] [--visibility <private | public>]
|
||||||
[--allow <did>] [--disallow <did>]
|
[--allow <did>] [--disallow <did>]
|
||||||
[--no-confirm] [--payload <id> <key> <val>...]
|
[--no-confirm] [--payload <id> <key> <val>...] [--edit] [<option>...]
|
||||||
[<option>...]
|
|
||||||
rad id edit <revision-id> [--title <string>] [--description <string>] [<option>...]
|
rad id edit <revision-id> [--title <string>] [--description <string>] [<option>...]
|
||||||
rad id show <revision-id> [<option>...]
|
rad id show <revision-id> [<option>...]
|
||||||
rad id <accept | reject | redact> <revision-id> [<option>...]
|
rad id <accept | reject | redact> <revision-id> [<option>...]
|
||||||
|
|
@ -64,6 +63,7 @@ pub enum Operation {
|
||||||
allow: BTreeSet<Did>,
|
allow: BTreeSet<Did>,
|
||||||
disallow: BTreeSet<Did>,
|
disallow: BTreeSet<Did>,
|
||||||
payload: Vec<(doc::PayloadId, String, json::Value)>,
|
payload: Vec<(doc::PayloadId, String, json::Value)>,
|
||||||
|
edit: bool,
|
||||||
},
|
},
|
||||||
AcceptRevision {
|
AcceptRevision {
|
||||||
revision: Rev,
|
revision: Rev,
|
||||||
|
|
@ -146,6 +146,7 @@ impl Args for Options {
|
||||||
let mut threshold: Option<usize> = None;
|
let mut threshold: Option<usize> = None;
|
||||||
let mut interactive = Interactive::new(io::stdout());
|
let mut interactive = Interactive::new(io::stdout());
|
||||||
let mut payload = Vec::new();
|
let mut payload = Vec::new();
|
||||||
|
let mut edit = false;
|
||||||
let mut quiet = false;
|
let mut quiet = false;
|
||||||
|
|
||||||
while let Some(arg) = parser.next()? {
|
while let Some(arg) = parser.next()? {
|
||||||
|
|
@ -237,6 +238,9 @@ impl Args for Options {
|
||||||
|
|
||||||
payload.push((id, key, val));
|
payload.push((id, key, val));
|
||||||
}
|
}
|
||||||
|
Long("edit") => {
|
||||||
|
edit = true;
|
||||||
|
}
|
||||||
Value(val) => {
|
Value(val) => {
|
||||||
let val = term::args::rev(&val)?;
|
let val = term::args::rev(&val)?;
|
||||||
revision = Some(val);
|
revision = Some(val);
|
||||||
|
|
@ -276,6 +280,7 @@ impl Args for Options {
|
||||||
allow,
|
allow,
|
||||||
disallow,
|
disallow,
|
||||||
payload,
|
payload,
|
||||||
|
edit,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
Ok((
|
Ok((
|
||||||
|
|
@ -385,6 +390,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
allow,
|
allow,
|
||||||
disallow,
|
disallow,
|
||||||
payload,
|
payload,
|
||||||
|
edit,
|
||||||
} => {
|
} => {
|
||||||
let proposal = {
|
let proposal = {
|
||||||
let mut proposal = current.doc.clone().edit();
|
let mut proposal = current.doc.clone().edit();
|
||||||
|
|
@ -416,8 +422,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(Visibility::Public, Some(EditVisibility::Private)) => {
|
(Visibility::Public, Some(EditVisibility::Private)) => {
|
||||||
// We ignore disallow since only allowing matters and
|
// We ignore disallow since only allowing matters and the sets are disjoint.
|
||||||
// the sets are disjoint
|
|
||||||
proposal.visibility = Visibility::Private { allow };
|
proposal.visibility = Visibility::Private { allow };
|
||||||
}
|
}
|
||||||
(Visibility::Private { .. }, Some(EditVisibility::Public)) if !allow.is_empty() || !disallow.is_empty() => {
|
(Visibility::Private { .. }, Some(EditVisibility::Public)) if !allow.is_empty() || !disallow.is_empty() => {
|
||||||
|
|
@ -462,8 +467,27 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
}
|
}
|
||||||
proposal
|
proposal
|
||||||
};
|
};
|
||||||
// Verify that the project payload can still be parsed into the
|
|
||||||
// `Project` type.
|
// If `--edit` is specified, the document can also be edited via a text edit.
|
||||||
|
let proposal = if edit {
|
||||||
|
match term::editor::Editor::comment()
|
||||||
|
.extension("json")
|
||||||
|
.initial(serde_json::to_string_pretty(¤t.doc)?)?
|
||||||
|
.edit()?
|
||||||
|
{
|
||||||
|
Some(proposal) => serde_json::from_str::<RawDoc>(&proposal)?,
|
||||||
|
None => {
|
||||||
|
term::print(term::format::italic(
|
||||||
|
"Nothing to do. The document is up to date. See `rad inspect --identity`.",
|
||||||
|
));
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
proposal
|
||||||
|
};
|
||||||
|
|
||||||
|
// Verify that the project payload can still be parsed into the `Project` type.
|
||||||
if let Err(PayloadError::Json(e)) = proposal.project() {
|
if let Err(PayloadError::Json(e)) = proposal.project() {
|
||||||
anyhow::bail!("failed to verify `xyz.radicle.project`, {e}");
|
anyhow::bail!("failed to verify `xyz.radicle.project`, {e}");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue