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 <self@cloudhead.io>
This commit is contained in:
Alexis Sellier 2023-01-09 16:37:39 +01:00
parent 1eb2a5ab9d
commit a6066e3ac3
No known key found for this signature in database
4 changed files with 32 additions and 21 deletions

View File

@ -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
```

View File

@ -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) => {

View File

@ -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::<Untrusted>::head(signer.public_key(), &repo)?;
let history = repo.revwalk(head)?.collect::<Vec<_>>();
let revision = history.len();
let history = repo.revwalk(head)?.collect::<Vec<_>>().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::<Unverified>::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)

View File

@ -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);
}