From a6066e3ac3ff2d84a6987d9efa469f32c40d64ac Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Mon, 9 Jan 2023 16:37:39 +0100 Subject: [PATCH] cli: Update `inspect` command Fix order of iteration, and make output look more like commit log. Also show commit parent and message. Signed-off-by: Alexis Sellier --- radicle-cli/examples/rad-init.md | 4 +-- radicle-cli/src/commands/init.rs | 4 +-- radicle-cli/src/commands/inspect.rs | 41 ++++++++++++++++++----------- radicle-cli/src/terminal/io.rs | 4 +-- 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/radicle-cli/examples/rad-init.md b/radicle-cli/examples/rad-init.md index 6844e0cc..40702208 100644 --- a/radicle-cli/examples/rad-init.md +++ b/radicle-cli/examples/rad-init.md @@ -16,10 +16,10 @@ ok Project heartwood created Your project id is rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji. You can show it any time by running: - rad . + rad . To publish your project to the network, run: - rad push + rad push ``` diff --git a/radicle-cli/src/commands/init.rs b/radicle-cli/src/commands/init.rs index cc5a6dd3..420dcd39 100644 --- a/radicle-cli/src/commands/init.rs +++ b/radicle-cli/src/commands/init.rs @@ -234,11 +234,11 @@ pub fn init(options: Options, profile: &profile::Profile) -> anyhow::Result<()> "Your project id is {}. You can show it any time by running:", term::format::highlight(id) ); - term::indented(&term::format::secondary("rad .")); + term::indented(term::format::secondary("rad .")); term::blank(); term::info!("To publish your project to the network, run:"); - term::indented(&term::format::secondary("rad push")); + term::indented(term::format::secondary("rad push")); term::blank(); } Err(err) => { diff --git a/radicle-cli/src/commands/inspect.rs b/radicle-cli/src/commands/inspect.rs index aadde067..ed7af3a0 100644 --- a/radicle-cli/src/commands/inspect.rs +++ b/radicle-cli/src/commands/inspect.rs @@ -149,10 +149,9 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { } else if options.history { let repo = storage.repository(id)?; let head = Doc::::head(signer.public_key(), &repo)?; - let history = repo.revwalk(head)?.collect::>(); - let revision = history.len(); + let history = repo.revwalk(head)?.collect::>().into_iter(); - for (counter, oid) in history.into_iter().rev().enumerate() { + for oid in history { let oid = oid?.into(); let tip = repo.commit(oid)?; let blob = Doc::::blob_at(oid, &repo)?; @@ -170,18 +169,30 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { .with_timezone(&timezone) .to_rfc2822(); - print!( - "{}", - term::TextBox::new(format!( - "commit {}\nblob {}\ndate {}\n\n{}", - term::format::yellow(oid), - term::format::dim(blob.id()), - term::format::dim(time), - colorizer().colorize_json_str(&serde_json::to_string_pretty(&content)?)?, - )) - .first(counter == 0) - .last(counter + 1 == revision) + println!( + "{} {}", + term::format::yellow("commit"), + term::format::yellow(oid), ); + if let Ok(parent) = tip.parent_id(0) { + println!("parent {}", parent); + } + println!("blob {}", blob.id()); + println!("date {}", time); + println!(); + + if let Some(msg) = tip.message() { + for line in msg.lines() { + term::indented(term::format::dim(line)); + } + term::blank(); + } + + let json = colorizer().colorize_json_str(&serde_json::to_string_pretty(&content)?)?; + for line in json.lines() { + println!(" {line}"); + } + println!(); } } else if options.id_only { term::info!("{}", term::format::highlight(id.to_human())); @@ -196,7 +207,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { fn colorizer() -> Colorizer { Colorizer::new() .null(Color::Cyan) - .boolean(Color::Yellow) + .boolean(Color::Cyan) .number(Color::Magenta) .string(Color::Green) .key(Color::Blue) diff --git a/radicle-cli/src/terminal/io.rs b/radicle-cli/src/terminal/io.rs index f8ea60ff..e8e8cff6 100644 --- a/radicle-cli/src/terminal/io.rs +++ b/radicle-cli/src/terminal/io.rs @@ -17,7 +17,7 @@ use super::format; use super::spinner::spinner; use super::Error; -pub const TAB: &str = " "; +pub const TAB: &str = " "; #[macro_export] macro_rules! info { @@ -103,7 +103,7 @@ pub fn eprintln(prefix: impl fmt::Display, msg: impl fmt::Display) { eprintln!("{} {}", prefix, msg); } -pub fn indented(msg: &str) { +pub fn indented(msg: impl fmt::Display) { println!("{}{}", TAB, msg); }