diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index f6320bc..4c0cdcf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,36 @@ -fn main() { - println!("Hello World"); +use anyhow::anyhow; +use anyhow::Result; +use clap::ArgMatches; + +use librepology::v1::api::*; +use librepology::v1::types::response::Problem; +use librepology::endpoint::DefaultEndpoint; + +mod cli; + +#[tokio::main] +async fn main() -> Result<()> { + let app = cli::app(); + + match app.get_matches().subcommand() { + ("problems", Some(mtch)) => problems(mtch).await, + (other, _) => Err(anyhow!("No such subcommand: {}", other)), + } +} + +async fn problems<'a>(matches: &ArgMatches<'a>) -> Result<()> { + let repo = matches.value_of("repo").map(String::from).unwrap(); // safe by clap + let client = ApiClient::new::<DefaultEndpoint>()?; + client.problems() + .for_repo(repo) + .to_request() + .perform() + .await? + .deserialize::<Vec<Problem>>()? + .into_iter() + .for_each(|problem| { + println!("Problem: {:?}", problem); + }); + + Ok(()) } |