Repository: peterheesterman/chit (language: rust)

Issue:
feat: Link to crates.rs and docs.rs
It would be nice to have the crates.io and documentation links available in the results.


Discussion / hints:

Fix patch:
diff --git a/src/extract.rs b/src/extract.rs
index 12fb515..8f771aa 100644
--- a/src/extract.rs
+++ b/src/extract.rs
@@ -12,13 +12,17 @@ pub struct Crate {
     pub downloads: Option<i64>,
     pub versions: Vec<Version>,
     pub recent_downloads: Option<i64>,
+    pub repository: String,
+    pub documentation: String,
 }
 
 pub fn crate_fields(json: serde_json::value::Value) -> Option<Crate> {
     let name = json["crate"]["name"].to_string();
     let downloads = json["crate"]["downloads"].as_i64();
     let recent_downloads = json["crate"]["recent_downloads"].as_i64();
-
+    let repository = json["crate"]["repository"].to_string();
+    let documentation = json["crate"]["documentation"].to_string();
+    
     if let Some(versions) = json["versions"].as_array() {
         let versions: Vec<Version> = versions
             .into_iter()
@@ -39,6 +43,8 @@ pub fn crate_fields(json: serde_json::value::Value) -> Option<Crate> {
             downloads,
             versions,
             recent_downloads,
+            repository,
+            documentation,
         })
     } else {
         None
diff --git a/src/main.rs b/src/main.rs
index 66d8294..c249060 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -83,12 +83,22 @@ fn main() {
 }
 
 fn chit(crate_name: String) {
-    let width = format::get_width();
+    let mut width = format::get_width();
     println!("{} {}...", "Searching for".magenta(), &crate_name.blue());
 
     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: {}",
+                    format::remove_quotes(fields.repository.clone())
+                );
+
+                if repository_details.len() > width {
+                    width = repository_details.len();
+                }
+
                 println!("{}", format::title_bar(width, &crate_name));
 
                 let rating = extract::calculate_rating(fields.clone());
@@ -111,6 +121,22 @@ fn chit(crate_name: String) {
                     )
                 );
 
+                if fields.documentation == "null" {
+                    format::print(
+                        format!("Docs: None specified in Cargo.toml")
+                    );
+                } else {
+                    format::print(
+                        format!("Docs: {}", format::remove_quotes(fields.documentation))
+                    );
+                }
+
+                format::print(repository_details);
+
+                format::print(
+                    format!("Crates.io: https://crates.io/crates/{}", &crate_name)
+                );
+
                 if let Some(size) = recent_version.size_in_bytes {
                     format::print(format!("Crate size: {} kB", (size as f64 / 1000_f64).round()));
                 }


Test patch: