radicle-heartwood-lfs/radicle-cli/src/commands/node/tracking.rs

49 lines
1.5 KiB
Rust

use radicle::node::{tracking, Handle as _};
use radicle::prelude::Did;
use radicle::Node;
use crate::terminal as term;
use super::TrackingMode;
pub fn run(node: &Node, mode: TrackingMode) -> anyhow::Result<()> {
match mode {
TrackingMode::Repos => print_repos(node)?,
TrackingMode::Nodes => print_nodes(node)?,
}
Ok(())
}
fn print_repos(node: &Node) -> anyhow::Result<()> {
let mut t = term::Table::new(term::table::TableOptions::default());
t.push(["RID", "Scope", "Policy"]);
t.push(["---", "-----", "------"]);
for tracking::Repo { id, scope, policy } in node.repo_policies()? {
t.push([
term::format::highlight(id.to_string()),
term::format::secondary(scope.to_string()),
term::format::secondary(policy.to_string()),
])
}
t.render();
Ok(())
}
fn print_nodes(node: &Node) -> anyhow::Result<()> {
let mut t = term::Table::new(term::table::TableOptions::default());
t.push(["DID", "Alias", "Policy"]);
t.push(["---", "-----", "------"]);
for tracking::Node { id, alias, policy } in node.node_policies()? {
t.push([
term::format::highlight(Did::from(id).to_string()),
match alias {
None => term::format::secondary("n/a".to_string()),
Some(alias) => term::format::secondary(alias),
},
term::format::secondary(policy.to_string()),
]);
}
t.render();
Ok(())
}