diff --git a/gdn-cli/src/commands/repo.rs b/gdn-cli/src/commands/repo.rs index e8bf2fc..5d7ec7a 100644 --- a/gdn-cli/src/commands/repo.rs +++ b/gdn-cli/src/commands/repo.rs @@ -1,4 +1,5 @@ mod add; +mod list; mod remove; mod show; @@ -9,6 +10,7 @@ use crate::Environment; /// Perform repo operations. #[derive(Debug, Parser)] pub enum Command { + List(list::Command), Show(show::Command), Add(add::Command), Remove(remove::Command), @@ -17,6 +19,7 @@ pub enum Command { impl Command { pub fn run(self, env: &Environment) -> anyhow::Result<()> { match self { + Self::List(command) => command.run(env), Self::Show(command) => command.run(env), Self::Add(command) => command.run(env), Self::Remove(command) => command.run(env), diff --git a/gdn-cli/src/commands/repo/list.rs b/gdn-cli/src/commands/repo/list.rs new file mode 100644 index 0000000..d0327fe --- /dev/null +++ b/gdn-cli/src/commands/repo/list.rs @@ -0,0 +1,32 @@ +use clap::Parser; + +use crate::Environment; + +/// List all repositories. +#[derive(Debug, Parser)] +pub struct Command {} + +impl Command { + pub fn run(self, env: &Environment) -> anyhow::Result<()> { + let data = gdn::data::open(env.data_dir.clone())?; + let state = gdn::data::load_state(&data)?; + + let mut repos = state + .repos + .into_iter() + .map(|(id, name)| (name, id)) + .collect::>(); + repos.sort_unstable(); + + if repos.is_empty() { + println!("No repos"); + } else { + println!("Repos: {}", repos.len()); + for (name, id) in repos { + println!("- {name} ({id })") + } + } + + Ok(()) + } +}