Merge branch 'cmdline-ls'

This commit is contained in:
asonix 2022-11-16 14:59:35 -06:00
commit 08374d0382
3 changed files with 21 additions and 0 deletions

View file

@ -11,6 +11,9 @@ pub(crate) struct Args {
#[arg(short, long, help = "Undo allowing or blocking domains")]
undo: bool,
#[arg(short, long, help = "List allowed and blocked domains")]
list: bool,
}
impl Args {
@ -29,4 +32,8 @@ impl Args {
pub(crate) fn undo(&self) -> bool {
self.undo
}
pub(crate) fn list(&self) -> bool {
self.list
}
}

View file

@ -464,6 +464,10 @@ impl Db {
self.unblock(|inner| Ok(inner.blocks().collect())).await
}
pub(crate) async fn allows(&self) -> Result<Vec<String>, Error> {
self.unblock(|inner| Ok(inner.allowed().collect())).await
}
pub(crate) async fn inboxes(&self) -> Result<Vec<IriString>, Error> {
self.unblock(|inner| Ok(inner.connected_actors().map(|actor| actor.inbox).collect()))
.await

View file

@ -101,6 +101,16 @@ async fn main() -> Result<(), anyhow::Error> {
let args = Args::new();
if args.list() {
for domain in db.blocks().await? {
println!("block {}", domain);
}
for domain in db.allows().await? {
println!("allow {}", domain);
}
return Ok(());
}
if !args.blocks().is_empty() || !args.allowed().is_empty() {
if args.undo() {
db.remove_blocks(args.blocks().to_vec()).await?;