Add repo list command
This commit is contained in:
parent
efafc085f3
commit
9a3004557f
2 changed files with 35 additions and 0 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
mod add;
|
mod add;
|
||||||
|
mod list;
|
||||||
mod remove;
|
mod remove;
|
||||||
mod show;
|
mod show;
|
||||||
|
|
||||||
|
|
@ -9,6 +10,7 @@ use crate::Environment;
|
||||||
/// Perform repo operations.
|
/// Perform repo operations.
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
|
List(list::Command),
|
||||||
Show(show::Command),
|
Show(show::Command),
|
||||||
Add(add::Command),
|
Add(add::Command),
|
||||||
Remove(remove::Command),
|
Remove(remove::Command),
|
||||||
|
|
@ -17,6 +19,7 @@ pub enum Command {
|
||||||
impl Command {
|
impl Command {
|
||||||
pub fn run(self, env: &Environment) -> anyhow::Result<()> {
|
pub fn run(self, env: &Environment) -> anyhow::Result<()> {
|
||||||
match self {
|
match self {
|
||||||
|
Self::List(command) => command.run(env),
|
||||||
Self::Show(command) => command.run(env),
|
Self::Show(command) => command.run(env),
|
||||||
Self::Add(command) => command.run(env),
|
Self::Add(command) => command.run(env),
|
||||||
Self::Remove(command) => command.run(env),
|
Self::Remove(command) => command.run(env),
|
||||||
|
|
|
||||||
32
gdn-cli/src/commands/repo/list.rs
Normal file
32
gdn-cli/src/commands/repo/list.rs
Normal file
|
|
@ -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::<Vec<_>>();
|
||||||
|
repos.sort_unstable();
|
||||||
|
|
||||||
|
if repos.is_empty() {
|
||||||
|
println!("No repos");
|
||||||
|
} else {
|
||||||
|
println!("Repos: {}", repos.len());
|
||||||
|
for (name, id) in repos {
|
||||||
|
println!("- {name} ({id })")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue