]> git.proxmox.com Git - cargo.git/commitdiff
Increase copypastafication of `cargo search`
authorCasey Rodarmor <casey@rodarmor.com>
Sat, 11 Feb 2017 02:50:17 +0000 (18:50 -0800)
committerCasey Rodarmor <casey@rodarmor.com>
Sat, 11 Feb 2017 02:50:17 +0000 (18:50 -0800)
Formats the search results printed by `cargo search` so that they can be
copied directly into a `Cargo.toml` file.

src/cargo/ops/registry.rs
tests/search.rs

index 5d35b71e3b7dc7c211051ca23b0e3e1fb20daed0..1a602a9d4a4a04aa0a0d66df8c4cb43aedaea949 100644 (file)
@@ -424,7 +424,7 @@ pub fn search(query: &str,
 
     let list_items = crates.iter()
         .map(|krate| (
-            format!("{} ({})", krate.name, krate.max_version),
+            format!("{} = \"^{}\"", krate.name, krate.max_version),
             krate.description.as_ref().map(|desc|
                 truncate_with_ellipsis(&desc.replace("\n", " "), 128))
         ))
@@ -439,7 +439,7 @@ pub fn search(query: &str,
             Some(desc) => {
                 let space = repeat(' ').take(description_margin - name.len())
                                        .collect::<String>();
-                name + &space + &desc
+                name + &space + "# " + &desc
             }
             None => name
         };
index b2f1c8ad1bcb3f947e8a3deeae84053e128027bd..4fd6678b0a66a62dead2602a9ac5b286941e75b4 100644 (file)
@@ -87,7 +87,7 @@ fn simple() {
                        .with_stderr("\
 [UPDATING] registry `[..]`")
                        .with_stdout("\
-hoare (0.1.1)    Design by contract style assertions for Rust"));
+hoare = \"^0.1.1\"    # Design by contract style assertions for Rust"));
 }
 
 #[test]
@@ -139,7 +139,7 @@ fn multiple_query_params() {
                        .with_stderr("\
 [UPDATING] registry `[..]`")
                        .with_stdout("\
-hoare (0.1.1)    Design by contract style assertions for Rust"));
+hoare = \"^0.1.1\"    # Design by contract style assertions for Rust"));
 }
 
 #[test]