Repository: peterheesterman/chit (language: rust)

Issue:
(feat) Add crate categories to the output
**Describe the solution you'd like**
Add crate categories to the output so i can tell what sort of crate this is that i am looking at.

(feat) Add crate categories to the output
**Describe the solution you'd like**
Add crate categories to the output so i can tell what sort of crate this is that i am looking at.



Discussion / hints:

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4f299e9..a486b41 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,9 @@
 
 # Change Log
 
+## 0.1.6 - 
+ - Add crate categories to the output
+ 
 ## 0.1.6 - The key is in the words
  - Refactor 
    - All the actions to their own file
diff --git a/src/chit/details.rs b/src/chit/details.rs
index af569e1..6716008 100644
--- a/src/chit/details.rs
+++ b/src/chit/details.rs
@@ -14,9 +14,17 @@ pub fn print_details(crate_name: String) {
                 // Asume repository is the longest field
                 let repository_details = format!("Repository: {}", &fields.repository);
 
-                if repository_details.len() > width {
-                    width = repository_details.len();
-                }
+                let keywords = format!("Keywords: {}", fields.keywords.join(", "));
+                let categories = format!("Categories: {}", fields.categories.join(", "));
+
+                let large_widths: Vec<usize> = vec![
+                    width,
+                    repository_details.len(),
+                    keywords.len(),
+                    categories.len(),
+                ];
+
+                width = *large_widths.iter().max().unwrap();
 
                 println!("{}", format::title_bar(width, &crate_name));
 
@@ -56,7 +64,8 @@ pub fn print_details(crate_name: String) {
                     ));
                 }
 
-                format::print(format!("Keywords: {}", fields.keywords.join(", ")));
+                format::print(keywords);
+                format::print(categories);
             }
         }
         None => {
diff --git a/src/chit/extract.rs b/src/chit/extract.rs
index af003b4..e725283 100644
--- a/src/chit/extract.rs
+++ b/src/chit/extract.rs
@@ -18,6 +18,16 @@ pub struct Crate {
     pub repository: String,
     pub documentation: String,
     pub keywords: Vec<String>,
+    pub categories: Vec<String>,
+}
+
+fn get_collect(key: &'static str, json: &serde_json::value::Value) -> Vec<String> {
+    json[key]
+        .as_array()
+        .unwrap()
+        .iter()
+        .map(|word| format::remove_quotes(word.to_string()))
+        .collect()
 }
 
 pub fn crate_fields(json: serde_json::value::Value) -> Option<Crate> {
@@ -26,13 +36,8 @@ pub fn crate_fields(json: serde_json::value::Value) -> Option<Crate> {
     let recent_downloads = json["crate"]["recent_downloads"].as_i64();
     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 keywords = get_collect("keywords", &json["crate"]);
+    let categories = get_collect("categories", &json["crate"]);
 
     let documentation = if documentation == "null" {
         format!("None specified in Cargo.toml")
@@ -64,6 +69,7 @@ pub fn crate_fields(json: serde_json::value::Value) -> Option<Crate> {
             repository,
             documentation,
             keywords,
+            categories,
         })
     } else {
         None


Test patch: