diff --git a/src/config.rs b/src/config.rs index 527c0d4..a7b9b33 100644 --- a/src/config.rs +++ b/src/config.rs @@ -16,8 +16,8 @@ pub struct Config { #[derive(Debug, Eq, PartialEq, Serialize, Deserialize)] /// The internal representation of a single repository pub struct Repository { - name: String, - url: String, + pub name: String, + pub url: String, } impl Repository { diff --git a/src/lib.rs b/src/lib.rs index 59ebf35..e3c355f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,6 +20,7 @@ enum Cmd { Add, Help, Fetch, + List, DumpConfig, } @@ -94,6 +95,15 @@ impl State { _ => {} } } + // list command + else if x == "list" { + match state.cmd { + None => { + state.cmd = Some(Cmd::List); + } + _ => {} + } + } arg = args.next(); } @@ -128,6 +138,21 @@ pub fn run(state: State, mut config: Config) -> Result<(), Box> { println!("Repository is already being tracked"); } } + Some(Cmd::List) => { + // Get the largest entry by name + let width: usize = match config + .repositories + .iter() + .max_by(|x, y| x.name.len().cmp(&y.name.len())) + { + Some(x) => x.name.len(), + None => 0, + }; + println!("{:width$} URL", "Name", width = width); + for repo in config.repositories.iter() { + println!("{:width$} {}", repo.name, repo.url, width = width); + } + } Some(x) => { println!("{:?} hasn't been implemented yet!", x) }