cli: add rad patch show

Show patch information with `rad patch show`.

Signed-off-by: Slack Coder <slackcoder@server.ky>
This commit is contained in:
Slack Coder
2023-01-20 13:46:02 +01:00
committed by Alexis Sellier
parent f5cb86dabd
commit 2295bb4ea4
5 changed files with 104 additions and 29 deletions
+1 -16
View File
@@ -238,23 +238,8 @@ pub fn run(
anyhow::bail!("a title must be given");
}
let title_pretty = &term::format::dim(format!("╭─ {} ───────", title));
term::blank();
term::print(title_pretty);
term::blank();
if description.is_empty() {
term::print(term::format::italic("No description provided."));
} else {
term::markdown(&description);
}
term::blank();
term::print(term::format::dim(format!(
"╰{}",
"─".repeat(term::text_width(title_pretty) - 1)
)));
term::patch::print_title_desc(title, &description);
term::blank();
if !confirm("Create patch?", &options) {
+35
View File
@@ -0,0 +1,35 @@
use super::common::*;
use super::*;
use crate::terminal as term;
use radicle::cob::patch;
use radicle::git;
use radicle::prelude::*;
use radicle::storage::git::Repository;
pub fn run(
storage: &Repository,
profile: &Profile,
workdir: &git::raw::Repository,
patch_id: &PatchId,
) -> anyhow::Result<()> {
let patches = patch::Patches::open(profile.public_key, storage)?;
let Some(patch) = patches.get(patch_id)? else {
anyhow::bail!("Patch `{}` not found", patch_id);
};
term::blank();
term::print(format!("patch {}", patch_id));
term::blank();
term::patch::print_title_desc(patch.title(), patch.description().unwrap_or(""));
term::blank();
let target_head = patch_merge_target_oid(patch.target(), storage)?;
let base_oid = workdir.merge_base(target_head, **patch.head())?;
let commits = patch_commits(workdir, &base_oid, patch.head())?;
term::patch::list_commits(&commits)?;
term::blank();
Ok(())
}