cli: reduce `rad ls` dependency

Fetch project information using the delegates fork of the project.  This
avoids expecting a user's fork to exist locally.

Delegate project information is expected to remain in sync.
This commit is contained in:
Slack Coder 2023-04-17 10:52:29 -05:00 committed by Alexis Sellier
parent 2598886018
commit 3e87e5f9eb
No known key found for this signature in database
2 changed files with 11 additions and 8 deletions

View File

@ -48,10 +48,11 @@ pub fn run(_options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
let storage = &profile.storage; let storage = &profile.storage;
let mut table = term::Table::default(); let mut table = term::Table::default();
storage.repositories()?.into_iter().for_each(|id| { for id in storage.repositories()? {
let Ok(repo) = storage.repository(id) else { return }; let Ok(repo) = storage.repository(id) else { continue };
let Ok((_, head)) = repo.head() else { return }; let Ok((_, head)) = repo.head() else { continue };
let Ok(proj) = repo.project_of(profile.id()) else { return }; let Ok(proj) = repo.project() else { continue };
let head = term::format::oid(head); let head = term::format::oid(head);
table.push([ table.push([
term::format::bold(proj.name().to_owned()), term::format::bold(proj.name().to_owned()),
@ -59,7 +60,7 @@ pub fn run(_options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
term::format::secondary(head), term::format::secondary(head),
term::format::italic(proj.description().to_owned()), term::format::italic(proj.description().to_owned()),
]); ]);
}); }
table.print(); table.print();
Ok(()) Ok(())

View File

@ -298,9 +298,11 @@ impl Repository {
Identity::load_at(head, self) Identity::load_at(head, self)
} }
pub fn project_of(&self, remote: &RemoteId) -> Result<Project, IdentityError> { /// Get the canonical project information.
let doc = self.identity_doc_of(remote)?; pub fn project(&self) -> Result<Project, IdentityError> {
let proj = doc.project()?; let head = self.identity_head()?;
let doc = self.identity_doc_at(head)?;
let proj = doc.verified()?.project()?;
Ok(proj) Ok(proj)
} }