diff --git a/Cargo.lock b/Cargo.lock index 6629c05..af5c53b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -269,6 +269,8 @@ dependencies = [ "libc", "log", "reqwest", + "serde", + "serde_json", "stderrlog", "structopt", ] @@ -875,6 +877,20 @@ name = "serde" version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] name = "serde_json" diff --git a/Cargo.toml b/Cargo.toml index 10a9408..b577138 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,8 @@ log = "0.4" stderrlog = "0.4" structopt = "0.3" reqwest = { version = "0.10", features = ["blocking", "json"] } +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" [target.'cfg(unix)'.dependencies] libc = "0.2" diff --git a/src/app.rs b/src/app.rs index 1f105fa..6ea779c 100644 --- a/src/app.rs +++ b/src/app.rs @@ -15,6 +15,7 @@ use log::{debug, error, info, trace, warn}; use crate::errors::*; use crate::gitignore::Gitignore; use crate::helpers::{git_dir, BoilerplateOpts, HELP_TEMPLATE}; +use crate::template::*; /// The verbosity level when no `-q` or `-v` arguments are given, with `0` being `-q` pub const DEFAULT_VERBOSITY: u64 = 1; @@ -100,16 +101,16 @@ fn run_get(lang: &str) -> Result<()> { /// Runs the command `list-templates` fn run_list_templates() -> Result<()> { let client = Client::new(); - let mut res = client + let res = client .get("https://api.github.com/repos/github/gitignore/contents//") .header(ACCEPT, "application/jsonapplication/vnd.github.v3+json") .header(CONTENT_TYPE, "application/json") .header(USER_AGENT, format!("{} {}", DEFAULT_USER_AGENT, env!("CARGO_PKG_VERSION"))) .send() .chain_err(|| "Error while sending request to query all templates")?; - println!("{:?}", &res); - let body = res.text().chain_err(|| "json")?; - println!("{:?}", &body); + let body: Vec