radicle_cli/commands/
unfollow.rs

1mod args;
2
3use radicle::node::Handle;
4
5use crate::terminal as term;
6
7pub use args::Args;
8pub(crate) use args::ABOUT;
9
10pub fn run(options: Args, ctx: impl term::Context) -> anyhow::Result<()> {
11    let profile = ctx.profile()?;
12    let mut node = radicle::Node::new(profile.socket());
13    let nid = options.nid;
14
15    let unfollowed = match node.unfollow(nid) {
16        Ok(updated) => updated,
17        Err(e) if e.is_connection_err() => {
18            let mut config = profile.policies_mut()?;
19            config.unfollow(&nid)?
20        }
21        Err(e) => return Err(e.into()),
22    };
23    if unfollowed {
24        term::success!("Follow policy for {} removed", term::format::tertiary(nid),);
25    }
26    Ok(())
27}