summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-04-07 17:49:17 +0200
committerMatthias Beyer <mail@beyermatthias.de>2021-04-07 17:49:17 +0200
commitd712ad9a51a433039cb9abcf85ef2d9ff1477279 (patch)
tree3dd0fac6a3eca71d81a551311d33704f184148d7
parent678442fda0cb58c91a53ddeeca6de5353e472b20 (diff)
Implement first CLI
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--Cargo.toml31
-rw-r--r--src/cli.rs25
-rw-r--r--src/main.rs37
3 files changed, 61 insertions, 32 deletions
diff --git a/Cargo.toml b/Cargo.toml
index a5ea631..3c2eea4 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -19,41 +19,12 @@ maintenance = { status = "actively-developed" }
librepology = { version = "0.1.0", path = "./librepology" }
anyhow = "1"
serde = "1"
-serde_derive = "1"
serde_json = "1"
-toml = "0.5"
-url = "1.7"
-url_serde = "0.2"
-xdg = "2"
log = "0.4"
-flexi_logger = "0.11"
-prettytable-rs = "0.8"
-filters = "0.3"
-boolinator = "2"
-itertools = "0.8"
-semver = "0.10"
+tokio = { version = "1", features = ["full"] }
[dependencies.clap]
version = ">=2.33"
default-features = false
features = [ "suggestions", "color", "wrap_help" ]
-[dependencies.csv]
-version = "1"
-optional = true
-
-[features]
-default = ["compare_csv"]
-compare_csv = ["csv"]
-
-[profile.release]
-opt-level = 3
-debug = false
-rpath = false
-lto = true
-debug-assertions = false
-codegen-units = 16
-panic = 'unwind'
-incremental = false
-overflow-checks = false
-
diff --git a/src/cli.rs b/src/cli.rs
new file mode 100644
index 0000000..6fa6a23
--- /dev/null
+++ b/src/cli.rs
@@ -0,0 +1,25 @@
+use clap::crate_authors;
+use clap::crate_version;
+use clap::App;
+use clap::Arg;
+
+pub fn app<'a, 'b>() -> App<'a, 'b> {
+ App::new("repolcli")
+ .author(crate_authors!())
+ .version(crate_version!())
+ .about("Repology CLI")
+
+ .subcommand(App::new("problems")
+ .version(crate_version!())
+ .about("Get problems of a project")
+
+ .arg(Arg::with_name("repo")
+ .index(1)
+ .required(true)
+ .multiple(false)
+ .value_name("REPO")
+ .help("Get problems for a repo REPO")
+ )
+ )
+}
+
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(())
}