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:
parent
1eb2a5ab9d
commit
a6066e3ac3
|
|
@ -16,10 +16,10 @@ ok Project heartwood created
|
||||||
|
|
||||||
|
|
||||||
Your project id is rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji. You can show it any time by running:
|
Your project id is rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji. You can show it any time by running:
|
||||||
rad .
|
rad .
|
||||||
|
|
||||||
To publish your project to the network, run:
|
To publish your project to the network, run:
|
||||||
rad push
|
rad push
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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:",
|
"Your project id is {}. You can show it any time by running:",
|
||||||
term::format::highlight(id)
|
term::format::highlight(id)
|
||||||
);
|
);
|
||||||
term::indented(&term::format::secondary("rad ."));
|
term::indented(term::format::secondary("rad ."));
|
||||||
|
|
||||||
term::blank();
|
term::blank();
|
||||||
term::info!("To publish your project to the network, run:");
|
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();
|
term::blank();
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
|
||||||
|
|
@ -149,10 +149,9 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
} else if options.history {
|
} else if options.history {
|
||||||
let repo = storage.repository(id)?;
|
let repo = storage.repository(id)?;
|
||||||
let head = Doc::<Untrusted>::head(signer.public_key(), &repo)?;
|
let head = Doc::<Untrusted>::head(signer.public_key(), &repo)?;
|
||||||
let history = repo.revwalk(head)?.collect::<Vec<_>>();
|
let history = repo.revwalk(head)?.collect::<Vec<_>>().into_iter();
|
||||||
let revision = history.len();
|
|
||||||
|
|
||||||
for (counter, oid) in history.into_iter().rev().enumerate() {
|
for oid in history {
|
||||||
let oid = oid?.into();
|
let oid = oid?.into();
|
||||||
let tip = repo.commit(oid)?;
|
let tip = repo.commit(oid)?;
|
||||||
let blob = Doc::<Unverified>::blob_at(oid, &repo)?;
|
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)
|
.with_timezone(&timezone)
|
||||||
.to_rfc2822();
|
.to_rfc2822();
|
||||||
|
|
||||||
print!(
|
println!(
|
||||||
"{}",
|
"{} {}",
|
||||||
term::TextBox::new(format!(
|
term::format::yellow("commit"),
|
||||||
"commit {}\nblob {}\ndate {}\n\n{}",
|
term::format::yellow(oid),
|
||||||
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)
|
|
||||||
);
|
);
|
||||||
|
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 {
|
} else if options.id_only {
|
||||||
term::info!("{}", term::format::highlight(id.to_human()));
|
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 {
|
fn colorizer() -> Colorizer {
|
||||||
Colorizer::new()
|
Colorizer::new()
|
||||||
.null(Color::Cyan)
|
.null(Color::Cyan)
|
||||||
.boolean(Color::Yellow)
|
.boolean(Color::Cyan)
|
||||||
.number(Color::Magenta)
|
.number(Color::Magenta)
|
||||||
.string(Color::Green)
|
.string(Color::Green)
|
||||||
.key(Color::Blue)
|
.key(Color::Blue)
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ use super::format;
|
||||||
use super::spinner::spinner;
|
use super::spinner::spinner;
|
||||||
use super::Error;
|
use super::Error;
|
||||||
|
|
||||||
pub const TAB: &str = " ";
|
pub const TAB: &str = " ";
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! info {
|
macro_rules! info {
|
||||||
|
|
@ -103,7 +103,7 @@ pub fn eprintln(prefix: impl fmt::Display, msg: impl fmt::Display) {
|
||||||
eprintln!("{} {}", prefix, msg);
|
eprintln!("{} {}", prefix, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn indented(msg: &str) {
|
pub fn indented(msg: impl fmt::Display) {
|
||||||
println!("{}{}", TAB, msg);
|
println!("{}{}", TAB, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue