Repository: peterheesterman/chit (language: rust)

Issue:
(feat) Add keywords to output
**Describe the solution you'd like**
I want the keywords of the crate to show up in the output so i can understand the crate a bit better



Discussion / hints:

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 577a853..f47467b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,7 +2,10 @@
 # Change Log
 
 ## 0.1.6 - 
- - Refactor all the actions to their own file
+ - Refactor 
+   - All the actions to their own file
+   - The remove_quote method usage
+ - Add keywords to the output
 
 ## 0.1.5 - A license to ... show
  - Include the software license for the shown crate
diff --git a/src/chit/details.rs b/src/chit/details.rs
index 9f6b336..af569e1 100644
--- a/src/chit/details.rs
+++ b/src/chit/details.rs
@@ -1,8 +1,8 @@
 use colored::*;
 
 use super::crates;
-use super::format;
 use super::extract;
+use super::format;
 
 pub fn print_details(crate_name: String) {
     let mut width = format::get_width();
@@ -11,11 +11,8 @@ pub fn print_details(crate_name: String) {
     match crates::get(crates::url(&crate_name)) {
         Some(crate_json) => {
             if let Some(fields) = extract::crate_fields(crate_json) {
-
                 // Asume repository is the longest field
-                let repository_details = format!("Repository: {}",
-                    &fields.repository
-                );
+                let repository_details = format!("Repository: {}", &fields.repository);
 
                 if repository_details.len() > width {
                     width = repository_details.len();
@@ -36,30 +33,30 @@ pub fn print_details(crate_name: String) {
                 }
 
                 let recent_version = &fields.versions[0];
-                format::print(
-                    format!("Latest version: {} ({})",
-                        recent_version.semver,
-                        recent_version.date
-                    )
-                );
+                format::print(format!(
+                    "Latest version: {} ({})",
+                    recent_version.semver, recent_version.date
+                ));
 
-                format::print(
-                    format!("Docs: {}", fields.documentation)
-                );
+                format::print(format!("Docs: {}", fields.documentation));
 
                 format::print(repository_details);
 
-                format::print(
-                    format!("Crates.io: https://crates.io/crates/{}", &crate_name)
-                );
+                format::print(format!(
+                    "Crates.io: https://crates.io/crates/{}",
+                    &crate_name
+                ));
 
-                format::print(
-                    format!("License: {}", recent_version.license)
-                );
+                format::print(format!("License: {}", recent_version.license));
 
                 if let Some(size) = recent_version.size_in_bytes {
-                    format::print(format!("Crate size: {} kB", (size as f64 / 1000_f64).round()));
+                    format::print(format!(
+                        "Crate size: {} kB",
+                        (size as f64 / 1000_f64).round()
+                    ));
                 }
+
+                format::print(format!("Keywords: {}", fields.keywords.join(", ")));
             }
         }
         None => {
@@ -82,13 +79,14 @@ pub fn print_details(crate_name: String) {
             let owners_names = owners_names.join(", ");
 
             // Owners
-            format::print(
-                format!("Owner{}: {}", if multiple { "s" } else { "" }, owners_names),
-            );
+            format::print(format!(
+                "Owner{}: {}",
+                if multiple { "s" } else { "" },
+                owners_names
+            ));
         }
         None => println!("Failed to get crate owner details"),
     }
 
     println!("{}", format::end_bar(width));
 }
-
diff --git a/src/chit/extract.rs b/src/chit/extract.rs
index 368d07e..af003b4 100644
--- a/src/chit/extract.rs
+++ b/src/chit/extract.rs
@@ -17,6 +17,7 @@ pub struct Crate {
     pub recent_downloads: Option<i64>,
     pub repository: String,
     pub documentation: String,
+    pub keywords: Vec<String>,
 }
 
 pub fn crate_fields(json: serde_json::value::Value) -> Option<Crate> {
@@ -26,10 +27,17 @@ pub fn crate_fields(json: serde_json::value::Value) -> Option<Crate> {
     let repository = format::remove_quotes(json["crate"]["repository"].to_string());
     let documentation = json["crate"]["documentation"].to_string();
 
+    let keywords = json["crate"]["keywords"]
+        .as_array()
+        .unwrap()
+        .iter()
+        .map(|word| format::remove_quotes(word.to_string()))
+        .collect();
+
     let documentation = if documentation == "null" {
-        format!("Docs: None specified in Cargo.toml")
+        format!("None specified in Cargo.toml")
     } else {
-        format!("Docs: {}", format::remove_quotes(documentation))
+        format::remove_quotes(documentation)
     };
 
     if let Some(versions) = json["versions"].as_array() {
@@ -46,7 +54,7 @@ pub fn crate_fields(json: serde_json::value::Value) -> Option<Crate> {
                     license: format::remove_quotes(version["license"].to_string()),
                 };
             })
-        .collect();
+            .collect();
 
         Some(Crate {
             name,
@@ -55,6 +63,7 @@ pub fn crate_fields(json: serde_json::value::Value) -> Option<Crate> {
             recent_downloads,
             repository,
             documentation,
+            keywords,
         })
     } else {
         None
diff --git a/src/chit/format.rs b/src/chit/format.rs
index ed275c8..27613ce 100644
--- a/src/chit/format.rs
+++ b/src/chit/format.rs
@@ -14,7 +14,7 @@ pub fn title_bar(width: usize, title: &str) -> String {
 }
 
 pub fn print(message: String) {
-    println!("{}",  &message.to_string().blue());
+    println!("{}", &message.to_string().blue());
 }
 
 pub fn end_bar(width: usize) -> String {
diff --git a/src/chit/mod.rs b/src/chit/mod.rs
index 07a8768..409fa48 100644
--- a/src/chit/mod.rs
+++ b/src/chit/mod.rs
@@ -1,9 +1,7 @@
-
 pub mod details;
 pub mod owners;
 pub mod versions;
 
 mod crates;
-mod format;
 mod extract;
-
+mod format;
diff --git a/src/chit/owners.rs b/src/chit/owners.rs
index 401ddc1..f3df633 100644
--- a/src/chit/owners.rs
+++ b/src/chit/owners.rs
@@ -18,24 +18,20 @@ pub fn print_owners(crate_name: String) {
                 .filter(|json| json["kind"] == "user")
             {
                 // Owner
-                format::print(
-                    format!(
-                        "Crates by {}:",
-                            format::remove_quotes(user_json["name"].to_string())
-                    ),
-                );
+                format::print(format!(
+                    "Crates by {}:",
+                    format::remove_quotes(user_json["name"].to_string())
+                ));
 
                 // Crates by owner
                 if let Some(user_id) = user_json["id"].as_u64() {
                     if let Some(user_json) = crates::get(crates::user_url(user_id)) {
                         if let Some(array) = user_json["crates"].as_array() {
                             for thing in array {
-                                format::print(
-                                    format!(
-                                        "    {}",
-                                        format::remove_quotes(thing["id"].to_string())
-                                    ),
-                                );
+                                format::print(format!(
+                                    "    {}",
+                                    format::remove_quotes(thing["id"].to_string())
+                                ));
                             }
                         }
                     }
@@ -47,4 +43,3 @@ pub fn print_owners(crate_name: String) {
 
     println!("{}", format::end_bar(width));
 }
-
diff --git a/src/chit/versions.rs b/src/chit/versions.rs
index 9c66c2c..6894e91 100644
--- a/src/chit/versions.rs
+++ b/src/chit/versions.rs
@@ -1,8 +1,8 @@
 use colored::*;
 
 use super::crates;
-use super::format;
 use super::extract;
+use super::format;
 
 pub fn print_versions(crate_name: String) {
     let width = format::get_width();
@@ -16,23 +16,15 @@ pub fn print_versions(crate_name: String) {
                 format::print(String::from("Versions:"));
                 for version in fields.versions {
                     if let Some(size) = version.size_in_bytes {
-                        format::print(
-                            format!(
-                                "    {}  ({}) | {} | {} kB",
-                                version.semver,
-                                version.license,
-                                version.date,
-                                (size as f64 / 1000_f64).round(),
-                            )
-                        );
+                        format::print(format!(
+                            "    {}  ({}) | {} | {} kB",
+                            version.semver,
+                            version.license,
+                            version.date,
+                            (size as f64 / 1000_f64).round(),
+                        ));
                     } else {
-                        format::print(
-                            format!(
-                                "    {} | {}",
-                                version.semver,
-                                version.date
-                            )
-                        );
+                        format::print(format!("    {} | {}", version.semver, version.date));
                     }
                 }
             }
diff --git a/src/main.rs b/src/main.rs
index 687db80..9b65ea8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,8 +2,8 @@ use clap::{App, Arg, SubCommand};
 use colored::*;
 use std::env;
 
-mod meta;
 mod chit;
+mod meta;
 
 fn main() {
     // subcommands
@@ -59,7 +59,7 @@ fn main() {
     // Actions
     if let Some(owners) = matches.subcommand_matches("owners") {
         if let Some(crate_name) = owners.value_of(crate_arg_name) {
-           chit::owners::print_owners(crate_name.to_string())
+            chit::owners::print_owners(crate_name.to_string())
         } else {
             println!("{}", "No crate supplied".yellow());
         };
@@ -79,4 +79,3 @@ fn main() {
         );
     }
 }
-
diff --git a/src/meta.rs b/src/meta.rs
index 75f6a1b..80133ae 100644
--- a/src/meta.rs
+++ b/src/meta.rs
@@ -1,8 +1,7 @@
-
 pub fn get_version() -> &'static str {
-	"0.1.5"
+    "0.1.5"
 }
 
 pub fn get_author() -> &'static str {
-	"Peter Heesterman <heesterman.peter@gmail.com>"
+    "Peter Heesterman <heesterman.peter@gmail.com>"
 }


Test patch: