radicle_cli/commands/
remote.rs1pub mod add;
4pub mod list;
5pub mod rm;
6
7mod args;
8
9use anyhow::anyhow;
10
11use radicle::storage::ReadStorage;
12
13use crate::terminal as term;
14use crate::terminal::Context;
15
16pub use args::Args;
17use args::{Command, ListOption};
18
19pub fn run(args: Args, ctx: impl Context) -> anyhow::Result<()> {
20 let (working, rid) = radicle::rad::cwd()
21 .map_err(|_| anyhow!("this command must be run in the context of a repository"))?;
22 let profile = ctx.profile()?;
23 let command = args
24 .command
25 .unwrap_or_else(|| Command::List(args.empty.into()));
26 match command {
27 Command::Add {
28 nid,
29 name,
30 fetch,
31 sync,
32 } => {
33 let proj = profile.storage.repository(rid)?.project()?;
34 let branch = proj.default_branch();
35 self::add::run(
36 rid,
37 &nid,
38 name,
39 Some(branch.clone()),
40 &profile,
41 &working,
42 fetch.should_fetch(),
43 sync.should_sync(),
44 )?
45 }
46 Command::Rm { ref name } => self::rm::run(name, &working)?,
47 Command::List(args) => match ListOption::from(args) {
48 ListOption::All => {
49 let tracked = list::tracked(&working)?;
50 let untracked = list::untracked(rid, &profile, tracked.iter())?;
51 let include_blank_line = !tracked.is_empty() && !untracked.is_empty();
53
54 list::print_tracked(tracked.iter());
55 if include_blank_line {
56 term::blank();
57 }
58 list::print_untracked(untracked.iter());
59 }
60 ListOption::Tracked => {
61 let tracked = list::tracked(&working)?;
62 list::print_tracked(tracked.iter());
63 }
64 ListOption::Untracked => {
65 let tracked = list::tracked(&working)?;
66 let untracked = list::untracked(rid, &profile, tracked.iter())?;
67 list::print_untracked(untracked.iter());
68 }
69 },
70 };
71 Ok(())
72}