diff --git a/Cargo.lock b/Cargo.lock index 77fece1fde..00a0b45f75 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,12 +4,12 @@ version = "0.1.6" dependencies = [ "assert_cli 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "clippy 0.0.140 (registry+https://github.com/rust-lang/crates.io-index)", - "curl 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", "docopt 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "pad 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "quick-error 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "reqwest 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "semver 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -17,6 +17,15 @@ dependencies = [ "toml 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "advapi32-sys" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "aho-corasick" version = "0.6.3" @@ -30,6 +39,11 @@ name = "ansi_term" version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "antidote" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "assert_cli" version = "0.2.2" @@ -39,6 +53,24 @@ dependencies = [ "difference 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "base64" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "bitflags" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "byteorder" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "cargo_metadata" version = "0.2.1" @@ -49,11 +81,6 @@ dependencies = [ "serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "cfg-if" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "clippy" version = "0.0.140" @@ -80,30 +107,29 @@ dependencies = [ ] [[package]] -name = "curl" -version = "0.4.7" +name = "core-foundation" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "curl-sys 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)", + "core-foundation-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-probe 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.9.14 (registry+https://github.com/rust-lang/crates.io-index)", - "socket2 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "curl-sys" -version = "0.3.13" +name = "core-foundation-sys" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)", - "libz-sys 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.9.14 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "vcpkg 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crypt32-sys" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -131,6 +157,11 @@ name = "dtoa" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "foreign-types" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "gcc" version = "0.3.51" @@ -141,6 +172,49 @@ name = "getopts" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "httparse" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "hyper" +version = "0.10.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "httparse 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", + "traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "hyper-native-tls" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "antidote 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.10.12 (registry+https://github.com/rust-lang/crates.io-index)", + "native-tls 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "idna" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-bidi 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "itoa" version = "0.3.1" @@ -155,6 +229,11 @@ dependencies = [ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "language-tags" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "lazy_static" version = "0.2.8" @@ -166,16 +245,18 @@ version = "0.2.24" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "libz-sys" -version = "1.0.16" +name = "libflate" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "vcpkg 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "log" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "matches" version = "0.1.6" @@ -190,9 +271,24 @@ dependencies = [ ] [[package]] -name = "nom" -version = "1.2.4" +name = "mime" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "native-tls" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "openssl 0.9.14 (registry+https://github.com/rust-lang/crates.io-index)", + "schannel 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "security-framework 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "security-framework-sys 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "num-traits" @@ -200,9 +296,24 @@ version = "0.1.39" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "openssl-probe" -version = "0.1.1" +name = "num_cpus" +version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "openssl" +version = "0.9.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "foreign-types 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys 0.9.14 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "openssl-sys" @@ -222,6 +333,11 @@ dependencies = [ "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "percent-encoding" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "pkg-config" version = "0.3.9" @@ -250,6 +366,11 @@ dependencies = [ "libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "redox_syscall" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "regex" version = "0.2.2" @@ -268,11 +389,61 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "semver" -version = "0.2.3" +name = "reqwest" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "hyper 0.10.12 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper-native-tls 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "libflate 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_urlencoded 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "schannel" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "advapi32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crypt32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "secur32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "secur32-sys" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "security-framework" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "core-foundation 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "core-foundation-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)", + "security-framework-sys 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "security-framework-sys" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "core-foundation-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -283,6 +454,15 @@ dependencies = [ "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "semver" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "semver-parser" version = "0.7.0" @@ -324,15 +504,14 @@ dependencies = [ ] [[package]] -name = "socket2" -version = "0.2.1" +name = "serde_urlencoded" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -384,6 +563,17 @@ dependencies = [ "unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "time" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "toml" version = "0.4.2" @@ -392,6 +582,32 @@ dependencies = [ "serde 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "traitobject" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "typeable" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "unicase" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "version_check 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "unicode-bidi" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "unicode-normalization" version = "0.1.5" @@ -415,14 +631,24 @@ dependencies = [ "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "url" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "idna 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "utf8-ranges" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "vcpkg" -version = "0.2.2" +name = "version_check" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -440,71 +666,88 @@ name = "winapi-build" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "ws2_32-sys" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [metadata] +"checksum advapi32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e06588080cb19d0acb6739808aafa5f26bfb2ca015b2b6370028b44cf7cb8a9a" "checksum aho-corasick 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "500909c4f87a9e52355b26626d890833e9e1d53ac566db76c36faa984b889699" "checksum ansi_term 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ae206c860259479b73b3abc98b66da811843056ed570ed79eb95d3d9b2524325" +"checksum antidote 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "34fde25430d87a9388dadbe6e34d7f72a462c8b43ac8d309b42b0a8505d7e2a5" "checksum assert_cli 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4b2ac77d8a259369d00b5b1a031fb142dcb269b910d2ebce9116a11680c13816" +"checksum base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "30e93c03064e7590d0466209155251b90c22e37fab1daf2771582598b5827557" +"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5" +"checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8" "checksum cargo_metadata 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5d84cb53c78e573aa126a4b9f963fdb2629f8183b26e235da08bb36dc7381162" -"checksum cfg-if 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c47d456a36ebf0536a6705c83c1cbbcb9255fbc1d905a6ded104f479268a29" "checksum clippy 0.0.140 (registry+https://github.com/rust-lang/crates.io-index)" = "c94943cf8c69a405dd21a0f2ce2311f1c8777a9e54422baaae2397b688d26c89" "checksum clippy_lints 0.0.140 (registry+https://github.com/rust-lang/crates.io-index)" = "116a24807a7704264f3bfcfcdc23a6d5196c2b37483281aa70c8e08c23a1b7d3" -"checksum curl 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "6689276ab61f97c660669a5ecc117c36875dfc1ba301c986b16c653415bdf9d7" -"checksum curl-sys 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)" = "cbd8b8d593de3bbf49252b92f398ef47f0c6c1ebdfd0f9282b9b9348aad8d71c" +"checksum core-foundation 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "25bfd746d203017f7d5cbd31ee5d8e17f94b6521c7af77ece6c9e4b2d4b16c67" +"checksum core-foundation-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "065a5d7ffdcbc8fa145d6f0746f3555025b9097a9e9cda59f7467abae670c78d" +"checksum crypt32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e34988f7e069e0b2f3bfc064295161e489b2d4e04a2e4248fb94360cdf00b4ec" "checksum difference 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ffef4c144e881a906ed5bd6e1e749dc1955cd3f0c7969d3d34122a971981c5ea" "checksum docopt 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3b5b93718f8b3e5544fcc914c43de828ca6c6ace23e0332c6080a2977b49787a" "checksum dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "80c8b71fd71146990a9742fc06dcbbde19161a267e0ad4e572c35162f4578c90" +"checksum foreign-types 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3e4056b9bd47f8ac5ba12be771f77a0dae796d1bbaaf5fd0b9c2d38b69b8a29d" "checksum gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)" = "120d07f202dcc3f72859422563522b66fe6463a4c513df062874daad05f85f0a" "checksum getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9047cfbd08a437050b363d35ef160452c5fe8ea5187ae0a624708c91581d685" +"checksum httparse 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "af2f2dd97457e8fb1ae7c5a420db346af389926e36f43768b96f101546b04a07" +"checksum hyper 0.10.12 (registry+https://github.com/rust-lang/crates.io-index)" = "0f01e4a20f5dfa5278d7762b7bdb7cab96e24378b9eca3889fbd4b5e94dc7063" +"checksum hyper-native-tls 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "72332e4a35d3059583623b50e98e491b78f8b96c5521fcb3f428167955aa56e8" +"checksum idna 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2233d4940b1f19f0418c158509cd7396b8d70a5db5705ce410914dc8fa603b37" "checksum itoa 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eb2f404fbc66fd9aac13e998248505e7ecb2ad8e44ab6388684c5fb11c6c251c" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +"checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" "checksum lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3b37545ab726dd833ec6420aaba8231c5b320814b9029ad585555d2a03e94fbf" "checksum libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)" = "38f5c2b18a287cf78b4097db62e20f43cace381dc76ae5c0a3073067f78b7ddc" -"checksum libz-sys 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)" = "3fdd64ef8ee652185674455c1d450b83cbc8ad895625d543b5324d923f82e4d8" +"checksum libflate 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "a2ee4762e65909ee9a4fbddbd2a4277575c7400d46f533db35202101946a09fe" +"checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" "checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" "checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4" -"checksum nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b8c256fd9471521bcb84c3cdba98921497f1a331cbc15b8030fc63b82050ce" +"checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" +"checksum native-tls 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04b781c9134a954c84f0594b9ab3f5606abc516030388e8511887ef4c204a1e5" "checksum num-traits 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "1708c0628602a98b52fad936cf3edb9a107af06e52e49fdf0707e884456a6af6" -"checksum openssl-probe 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d98df0270d404ccd3c050a41d579c52d1db15375168bb3471e04ec0f5f378daf" +"checksum num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "aec53c34f2d0247c5ca5d32cca1478762f301740468ee9ee6dcb7a0dd7a0c584" +"checksum openssl 0.9.14 (registry+https://github.com/rust-lang/crates.io-index)" = "11ba043cb65fc9af71a431b8a36ffe8686cd4751cdf70a473ec1d01066ac7e41" "checksum openssl-sys 0.9.14 (registry+https://github.com/rust-lang/crates.io-index)" = "236c718c2e2c2b58a546d86ffea5194400bb15dbe01ca85325ffd357b03cf66c" "checksum pad 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d1bf3336e626b898e7263790d432a711d4277e22faea20dd9f70e0cab268fa58" +"checksum percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de154f638187706bde41d9b4738748933d64e6b37bdbffc0b47a97d16a6ae356" "checksum pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3a8b4c6b8165cd1a1cd4b9b120978131389f64bdaf456435caa41e630edba903" "checksum quick-error 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c36987d4978eb1be2e422b1e0423a557923a5c3e7e6f31d5699e9aafaefa469" "checksum quine-mc_cluskey 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "07589615d719a60c8dd8a4622e7946465dfef20d1a428f969e3443e7386d5f45" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" "checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d" +"checksum redox_syscall 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "3041aeb6000db123d2c9c751433f526e1f404b23213bd733167ab770c3989b4d" "checksum regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1731164734096285ec2a5ec7fea5248ae2f5485b3feeb0115af4fda2183b2d1b" "checksum regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad890a5eef7953f55427c50575c680c42841653abd2b028b68cd223d157f62db" -"checksum semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2d5b7638a1f03815d94e88cb3b3c08e87f0db4d683ef499d1836aaf70a45623f" +"checksum reqwest 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1d56dbe269dbe19d716b76ec8c3efce8ef84e974f5b7e5527463e8c0507d4e17" +"checksum schannel 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "14a5f8491ae5fc8c51aded1f5806282a0218b4d69b1b76913a0559507e559b90" +"checksum secur32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3f412dfa83308d893101dd59c10d6fda8283465976c28c287c5c855bf8d216bc" +"checksum security-framework 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "42ddf098d78d0b64564b23ee6345d07573e7d10e52ad86875d89ddf5f8378a02" +"checksum security-framework-sys 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "5bacdada57ea62022500c457c8571c17dfb5e6240b7c8eac5916ffa8c7138a55" "checksum semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a3186ec9e65071a2095434b1f5bb24838d4e8e130f584c790f6033c79943537" +"checksum semver 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3fdd61b85a0fa777f7fb7c454b9189b2941b110d1385ce84d7f76efdf1606a85" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum serde 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "c2f530d36fb84ec48fb7146936881f026cdbf4892028835fd9398475f82c1bb4" "checksum serde_derive 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "10552fad5500771f3902d0c5ba187c5881942b811b7ba0d8fbbfbf84d80806d3" "checksum serde_derive_internals 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)" = "37aee4e0da52d801acfbc0cc219eb1eda7142112339726e427926a6f6ee65d3a" "checksum serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "48b04779552e92037212c3615370f6bd57a40ebba7f20e554ff9f55e41a69a7b" -"checksum socket2 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "12cdbddbaa27bf94cc194b8e37f5811db6fe83cea96cf99cf1f8e92b65a41371" +"checksum serde_urlencoded 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ce0fd303af908732989354c6f02e05e2e6d597152870f2c6990efb0577137480" "checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694" "checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" "checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" "checksum tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "87974a6f5c1dfb344d733055601650059a3363de2a6104819293baff662132d6" "checksum thread-id 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8df7875b676fddfadffd96deea3b1124e5ede707d4884248931077518cf1f773" "checksum thread_local 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c85048c6260d17cf486ceae3282d9fb6b90be220bf5b28c400f5485ffc29f0c7" +"checksum time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "ffd7ccbf969a892bf83f1e441126968a07a3941c24ff522a26af9f9f4585d1a3" "checksum toml 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b0601da6c97135c8d330c7a13a013ca6cd4143221b01de2f8d4edc50a9e551c7" +"checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" +"checksum typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" +"checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" +"checksum unicode-bidi 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a6a2c4e3710edd365cd7e78383153ed739fa31af19f9172f72d3575060f5a43a" "checksum unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "51ccda9ef9efa3f7ef5d91e8f9b83bbe6955f9bf86aec89d5cce2c874625920f" "checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f" "checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" "checksum unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2ae5ddb18e1c92664717616dd9549dde73f539f01bd7b77c2edb2446bdff91" +"checksum url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eeb819346883532a271eb626deb43c4a1bb4c4dd47c519bd78137c3e72a4fe27" "checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122" -"checksum vcpkg 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9e0a7d8bed3178a8fb112199d466eeca9ed09a14ba8ad67718179b4fd5487d0b" +"checksum version_check 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2bb3950bf29e36796dea723df1747619dd331881aefef75b7cf1c58fdd738afe" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" -"checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" diff --git a/Cargo.toml b/Cargo.toml index ec58526035..aae6fc2250 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,11 +39,11 @@ pad = "0.1" serde = "1.0" serde_derive = "1.0" serde_json = "1.0" -semver = "0.2" +semver = { version = "0.7", features = ["serde"] } toml = "0.4" -curl = "0.4.7" quick-error = "1.0.0" regex = "0.2" +reqwest = "0.6" clippy = {version = "0.0.140", optional = true} [dev-dependencies] diff --git a/src/bin/add/args.rs b/src/bin/add/args.rs index bde20839f2..58444dbc3e 100644 --- a/src/bin/add/args.rs +++ b/src/bin/add/args.rs @@ -62,9 +62,9 @@ impl Args { let mut result = Vec::::new(); for arg_crate in &self.arg_crates { let le_crate = if crate_name_has_version(arg_crate) { - try!(parse_crate_name_with_version(arg_crate)) + parse_crate_name_with_version(arg_crate)? } else { - try!(get_latest_dependency(arg_crate, self.flag_allow_prerelease)) + get_latest_dependency(arg_crate, self.flag_allow_prerelease)? } .set_optional(self.flag_optional); @@ -74,7 +74,7 @@ impl Args { } if crate_name_has_version(&self.arg_crate) { - return Ok(vec![try!(parse_crate_name_with_version(&self.arg_crate)) + return Ok(vec![parse_crate_name_with_version(&self.arg_crate)? .set_optional(self.flag_optional)]); } @@ -83,14 +83,14 @@ impl Args { let dependency = Dependency::new(&self.arg_crate); if let Some(ref version) = self.flag_vers { - try!(semver::VersionReq::parse(version)); + semver::VersionReq::parse(version)?; dependency.set_version(version) } else if let Some(ref repo) = self.flag_git { dependency.set_git(repo) } else if let Some(ref path) = self.flag_path { dependency.set_path(path) } else { - let dep = try!(get_latest_dependency(&self.arg_crate, self.flag_allow_prerelease)); + let dep = get_latest_dependency(&self.arg_crate, self.flag_allow_prerelease)?; let v = format!("{prefix}{version}", prefix = self.get_upgrade_prefix().unwrap_or(""), // if version is unavailable @@ -99,7 +99,7 @@ impl Args { dep.set_version(&v) } } else { - try!(parse_crate_name_from_uri(&self.arg_crate)) + parse_crate_name_from_uri(&self.arg_crate)? } .set_optional(self.flag_optional); @@ -168,7 +168,7 @@ fn parse_crate_name_with_version(name: &str) -> Result> { let xs: Vec<&str> = name.splitn(2, '@').collect(); let (name, version) = (xs[0], xs[1]); - try!(semver::VersionReq::parse(version)); + semver::VersionReq::parse(version)?; Ok(Dependency::new(name).set_version(version)) } diff --git a/src/bin/add/fetch.rs b/src/bin/add/fetch.rs index 194de3466b..f5daf9c43f 100644 --- a/src/bin/add/fetch.rs +++ b/src/bin/add/fetch.rs @@ -1,14 +1,31 @@ use cargo_edit::{Dependency, Manifest}; -use curl; -use curl::easy::Easy; use regex::Regex; +use reqwest; +use semver; +#[cfg(test)] use serde_json as json; -use semver::Version; use std::env; +use std::io; +use std::io::Read; use std::path::Path; +use std::time::Duration; const REGISTRY_HOST: &'static str = "https://crates.io"; +#[derive(Deserialize)] +struct Versions { + versions: Vec, +} + +#[derive(Deserialize)] +struct CrateVersion { + #[serde(rename = "crate")] + name: String, + #[serde(rename = "num")] + version: semver::Version, + yanked: bool, +} + /// Query latest version from crates.io /// /// The latest version will be returned as a `Dependency`. This will fail, when @@ -16,18 +33,22 @@ const REGISTRY_HOST: &'static str = "https://crates.io"; /// - there is no Internet connection, /// - the response from crates.io is an error or in an incorrect format, /// - or when a crate with the given name does not exist on crates.io. -pub fn get_latest_dependency(crate_name: &str, flag_allow_prerelease: bool) -> Result { +pub fn get_latest_dependency( + crate_name: &str, + flag_allow_prerelease: bool, +) -> Result { if env::var("CARGO_IS_TEST").is_ok() { // We are in a simulated reality. Nothing is real here. // FIXME: Use actual test handling code. - return Ok(Dependency::new(crate_name) - .set_version(&format!("{}--CURRENT_VERSION_TEST", crate_name))); + return Ok(Dependency::new(crate_name).set_version(&format!( + "{}--CURRENT_VERSION_TEST", + crate_name + ))); } - let crate_data = try!(fetch_cratesio(&format!("/crates/{}", crate_name))); - let crate_json = try!(json::from_str(&crate_data)); + let crate_versions = fetch_cratesio(&format!("/crates/{}", crate_name))?; - let dep = try!(read_latest_version(&crate_json, flag_allow_prerelease)); + let dep = read_latest_version(&crate_versions, flag_allow_prerelease)?; if dep.name != crate_name { println!("WARN: Added `{}` instead of `{}`", dep.name, crate_name); @@ -37,46 +58,34 @@ pub fn get_latest_dependency(crate_name: &str, flag_allow_prerelease: bool) -> R } // Checks whether a version object is a stable release -fn version_is_stable(version: &json::Value) -> bool { - version.get("num") - .and_then(json::Value::as_str) - .and_then(|s| Version::parse(s).ok()) - .map(|s| !s.is_prerelease()) - .unwrap_or(false) +fn version_is_stable(version: &CrateVersion) -> bool { + !version.version.is_prerelease() } -/// Read latest version from JSON structure +/// Read latest version from Versions structure /// /// Assumes the version are sorted so that the first non-yanked version is the /// latest, and thus the one we want. -fn read_latest_version(crate_json: &json::Value, flag_allow_prerelease: bool) -> Result { - let versions = try!(crate_json.as_object() - .and_then(|c| c.get("versions")) - .and_then(json::Value::as_array) - .ok_or(FetchVersionError::GetVersion)); - - let latest = try!(versions.iter() - .filter(|v| json::Value::is_object(*v)) +fn read_latest_version( + versions: &Versions, + flag_allow_prerelease: bool, +) -> Result { + let latest = versions + .versions + .iter() .filter(|&v| flag_allow_prerelease || version_is_stable(v)) - .find(|&v| !v.get("yanked").and_then(json::Value::as_bool).unwrap_or(true)) - .ok_or(FetchVersionError::NoneAvailable)); - - let name = try!(latest.get("crate") - .and_then(json::Value::as_str) - .map(String::from) - .ok_or(FetchVersionError::NotFound)); + .find(|&v| !v.yanked) + .ok_or(FetchVersionError::GetVersion)?; - let version = try!(latest.get("num") - .and_then(json::Value::as_str) - .map(String::from) - .ok_or(FetchVersionError::GetVersion)); - - Ok(Dependency::new(&name).set_version(&version)) + let name = &latest.name; + let version = latest.version.to_string(); + Ok(Dependency::new(name).set_version(&version)) } #[test] fn get_latest_stable_version_from_json() { - let json = json::from_str(r#"{ + let versions: Versions = json::from_str( + r#"{ "versions": [ { "crate": "foo", @@ -89,16 +98,22 @@ fn get_latest_stable_version_from_json() { "yanked": false } ] - }"#) - .unwrap(); - - assert_eq!(read_latest_version(&json, false).unwrap().version().unwrap(), - "0.5.0"); + }"#, + ).expect("crate version is correctly parsed"); + + assert_eq!( + read_latest_version(&versions, false) + .unwrap() + .version() + .unwrap(), + "0.5.0" + ); } #[test] fn get_latest_unstable_or_stable_version_from_json() { - let json = json::from_str(r#"{ + let versions: Versions = json::from_str( + r#"{ "versions": [ { "crate": "foo", @@ -111,16 +126,22 @@ fn get_latest_unstable_or_stable_version_from_json() { "yanked": false } ] - }"#) - .unwrap(); - - assert_eq!(read_latest_version(&json, true).unwrap().version().unwrap(), - "0.6.0-alpha"); + }"#, + ).expect("crate version is correctly parsed"); + + assert_eq!( + read_latest_version(&versions, true) + .unwrap() + .version() + .unwrap(), + "0.6.0-alpha" + ); } #[test] fn get_latest_version_from_json_test() { - let json = json::from_str(r#"{ + let versions: Versions = json::from_str( + r#"{ "versions": [ { "crate": "treexml", @@ -133,16 +154,22 @@ fn get_latest_version_from_json_test() { "yanked": false } ] - }"#) - .unwrap(); - - assert_eq!(read_latest_version(&json, false).unwrap().version().unwrap(), - "0.3.0"); + }"#, + ).expect("crate version is correctly parsed"); + + assert_eq!( + read_latest_version(&versions, false) + .unwrap() + .version() + .unwrap(), + "0.3.0" + ); } #[test] fn get_no_latest_version_from_json_when_all_are_yanked() { - let json = json::from_str(r#"{ + let versions: Versions = json::from_str( + r#"{ "versions": [ { "crate": "treexml", @@ -155,88 +182,46 @@ fn get_no_latest_version_from_json_when_all_are_yanked() { "yanked": true } ] - }"#) - .unwrap(); + }"#, + ).expect("crate version is correctly parsed"); - assert!(read_latest_version(&json, false).is_err()); + assert!(read_latest_version(&versions, false).is_err()); } quick_error! { #[derive(Debug)] pub enum FetchVersionError { - Curl(err: curl::Error) { + Reqwest(err: reqwest::Error) { from() - description("Curl error") - display("Curl error: {}", err) - cause(err) - } - NonUtf8(err: ::std::string::FromUtf8Error) { - from() - description("Curl error") - display("Curl error: {}", err) - cause(err) - } - NotFound {} - Json(err: json::Error) { - from() - description("JSON Error") - display("Error parsing JSON: {}", err) + description("Http error") + display("Http error: {}", err) cause(err) } GetVersion { description("get version error") } - NoneAvailable { description("No available versions exist. Either all were yanked or only \ - prerelease versions exist. Trying with the --fetch-prereleases flag might solve \ - the issue.") } } } -// --- -// The following was mostly copied from [1] and is therefore -// (c) 2015 Alex Crichton -// -// [1]: https://github.com/rust-lang/cargo/blob/bd690d8dff83c7b7714f236a08304ee20732382b/src/crates-io/lib.rs -// --- - -fn fetch_cratesio(path: &str) -> Result { - let mut easy = Easy::new(); - easy.url(&format!("{}/api/v1{}", REGISTRY_HOST, path))?; - easy.get(true)?; - easy.accept_encoding("application/json")?; - - let mut html = Vec::new(); - { - let mut transfer = easy.transfer(); - transfer.write_function(|data| { - html.extend_from_slice(data); - Ok(data.len()) - })?; - - - transfer.perform()?; - } - - String::from_utf8(html).map_err(FetchVersionError::NonUtf8) +fn fetch_cratesio(path: &str) -> Result { + let url = format!("{host}/api/v1{path}", host = REGISTRY_HOST, path = path); + let mut response = get_with_timeout(&url, get_default_timeout())?; + let versions: Versions = response.json()?; + Ok(versions) } #[cfg_attr(rustfmt, rustfmt_skip)] quick_error! { #[derive(Debug)] pub enum FetchGitError { - FetchGit(err: curl::Error) { + FetchGit(err: reqwest::Error) { from() description("fetch error: ") display("fetch error: {}", err) cause(err) } - StringWrite(err: curl::easy::WriteError) { - from() - description("string write error: ") - display("string write error: {:?}", err) - } - NonUtf8(err: ::std::string::FromUtf8Error) { + Io(err: io::Error) { from() - description("Curl error") - display("Curl error: {}", err) + description("io error: ") + display("io error: {}", err) cause(err) } ParseRegex { description("parse error: unable to parse git repo url") } @@ -247,6 +232,29 @@ quick_error! { } } +fn get_crate_name_from_repository( + repo: &str, + matcher: &Regex, + url_template: T, +) -> Result +where + T: Fn(&str, &str) -> String, +{ + matcher + .captures(repo) + .ok_or(FetchGitError::ParseRegex) + .and_then(|cap| match (cap.get(1), cap.get(2)) { + (Some(user), Some(repo)) => { + let url = url_template(user.as_str(), repo.as_str()); + let data: Result = get_cargo_toml_from_git_url(&url).and_then(|m| { + m.parse().map_err(|_| FetchGitError::ParseCargoToml) + }); + data.and_then(|ref manifest| get_name_from_manifest(manifest)) + } + _ => Err(FetchGitError::IncompleteCaptures), + }) +} + /// Query crate name by accessing a github repo Cargo.toml /// /// The name will be returned as a string. This will fail, when @@ -255,28 +263,16 @@ quick_error! { /// - Cargo.toml is not present in the root of the master branch, /// - the response from github is an error or in an incorrect format. pub fn get_crate_name_from_github(repo: &str) -> Result { - let re = Regex::new(r"^https://github.com/([-_0-9a-zA-Z]+)/([-_0-9a-zA-Z]+)(/|.git)?$") - .unwrap(); - - re.captures(repo) - .ok_or(FetchGitError::ParseRegex) - .and_then(|cap| { - match (cap.get(1), cap.get(2)) { - (Some(user), Some(repo)) => { - let url = format!("https://raw.githubusercontent.com/{}/{}/master/Cargo.toml", - user.as_str(), - repo.as_str()); - - let data: Result = get_cargo_toml_from_git_url(&url) - .and_then(|m| { - m.parse() - .map_err(|_| FetchGitError::ParseCargoToml) - }); - data.and_then(|ref manifest| get_name_from_manifest(manifest)) - } - _ => Err(FetchGitError::IncompleteCaptures), - } - }) + let re = Regex::new( + r"^https://github.com/([-_0-9a-zA-Z]+)/([-_0-9a-zA-Z]+)(/|.git)?$", + ).unwrap(); + get_crate_name_from_repository(repo, &re, |user, repo| { + format!( + "https://raw.githubusercontent.com/{user}/{repo}/master/Cargo.toml", + user = user, + repo = repo + ) + }) } /// Query crate name by accessing a gitlab repo Cargo.toml @@ -287,28 +283,16 @@ pub fn get_crate_name_from_github(repo: &str) -> Result { /// - Cargo.toml is not present in the root of the master branch, /// - the response from gitlab is an error or in an incorrect format. pub fn get_crate_name_from_gitlab(repo: &str) -> Result { - let re = Regex::new(r"^https://gitlab.com/([-_0-9a-zA-Z]+)/([-_0-9a-zA-Z]+)(/|.git)?$") - .unwrap(); - - re.captures(repo) - .ok_or(FetchGitError::ParseRegex) - .and_then(|cap| { - match (cap.get(1), cap.get(2)) { - (Some(user), Some(repo)) => { - let url = format!("https://gitlab.com/{}/{}/raw/master/Cargo.toml", - user.as_str(), - repo.as_str()); - - let data: Result = get_cargo_toml_from_git_url(&url) - .and_then(|m| { - m.parse() - .map_err(|_| FetchGitError::ParseCargoToml) - }); - data.and_then(|ref manifest| get_name_from_manifest(manifest)) - } - _ => Err(FetchGitError::IncompleteCaptures), - } - }) + let re = Regex::new( + r"^https://gitlab.com/([-_0-9a-zA-Z]+)/([-_0-9a-zA-Z]+)(/|.git)?$", + ).unwrap(); + get_crate_name_from_repository(repo, &re, |user, repo| { + format!( + "https://gitlab.com/{user}/{repo}/raw/master/Cargo.toml", + user = user, + repo = repo + ) + }) } /// Query crate name by accessing Cargo.toml in a local path @@ -323,30 +307,27 @@ pub fn get_crate_name_from_path(path: &str) -> Result { } fn get_name_from_manifest(manifest: &Manifest) -> Result { - manifest.data + manifest + .data .get("package") .and_then(|m| m.get("name")) .and_then(|name| name.as_str().map(|s| s.to_string())) .ok_or(FetchGitError::ParseCargoToml) } -fn get_cargo_toml_from_git_url(url: &str) -> Result { - let mut easy = Easy::new(); - easy.url(url)?; - easy.get(true)?; - easy.accept_encoding("text/plain")?; - - let mut html = Vec::new(); - { - let mut transfer = easy.transfer(); - transfer.write_function(|data| { - html.extend_from_slice(data); - Ok(data.len()) - })?; - +fn get_default_timeout() -> Duration { + Duration::from_secs(10) +} - transfer.perform()?; - } +fn get_with_timeout(url: &str, timeout: Duration) -> reqwest::Result { + let mut client = reqwest::Client::new()?; + client.timeout(timeout); + client.get(url).send() +} - String::from_utf8(html).map_err(FetchGitError::NonUtf8) +fn get_cargo_toml_from_git_url(url: &str) -> Result { + let mut res = get_with_timeout(url, get_default_timeout())?; + let mut body = String::new(); + res.read_to_string(&mut body)?; + Ok(body) } diff --git a/src/bin/add/main.rs b/src/bin/add/main.rs index 6c7be4c63e..c01e318931 100644 --- a/src/bin/add/main.rs +++ b/src/bin/add/main.rs @@ -5,12 +5,13 @@ #![cfg_attr(feature = "dev", feature(plugin))] #![cfg_attr(feature = "dev", plugin(clippy))] -extern crate curl; +extern crate reqwest; extern crate docopt; extern crate toml; -extern crate semver; #[macro_use] extern crate serde_derive; +extern crate semver; +extern crate serde; extern crate serde_json; #[macro_use] extern crate quick_error; @@ -72,8 +73,8 @@ dependencies (version set to "*"). "#; fn handle_add(args: &Args) -> Result<(), Box> { - let mut manifest = try!(Manifest::open(&args.flag_manifest_path.as_ref().map(|s| &s[..]))); - let deps = try!(args.parse_dependencies()); + let mut manifest = Manifest::open(&args.flag_manifest_path.as_ref().map(|s| &s[..]))?; + let deps = args.parse_dependencies()?; deps .iter() @@ -87,7 +88,7 @@ fn handle_add(args: &Args) -> Result<(), Box> { err })?; - let mut file = try!(Manifest::find_file(&args.flag_manifest_path.as_ref().map(|s| &s[..]))); + let mut file = Manifest::find_file(&args.flag_manifest_path.as_ref().map(|s| &s[..]))?; manifest.write_to_file(&mut file) } diff --git a/src/bin/list/list.rs b/src/bin/list/list.rs index a5972a44b0..fd958cc525 100644 --- a/src/bin/list/list.rs +++ b/src/bin/list/list.rs @@ -10,10 +10,10 @@ use toml; pub fn list_section(manifest: &Manifest, section: &str) -> Result { let mut output = vec![]; - let list = try!(manifest.data + let list = manifest.data .get(section) .and_then(|field| field.as_table()) - .ok_or_else(|| ListError::SectionMissing(String::from(section)))); + .ok_or_else(|| ListError::SectionMissing(String::from(section)))?; let name_max_len = list.keys().map(|k| k.len()).max().unwrap_or(0); @@ -21,11 +21,11 @@ pub fn list_section(manifest: &Manifest, section: &str) -> Result version.clone(), toml::Value::Table(_) => { - try!(val.get("version") + val.get("version") .and_then(|field| field.as_str().map(|s| s.to_owned())) .or_else(|| val.get("git").map(|repo| format!("git: {}", repo))) .or_else(|| val.get("path").map(|path| format!("path: {}", path))) - .ok_or_else(|| ListError::VersionMissing(name.clone(), section.to_owned()))) + .ok_or_else(|| ListError::VersionMissing(name.clone(), section.to_owned()))? } _ => String::from(""), }; diff --git a/src/bin/list/main.rs b/src/bin/list/main.rs index bd5b453fef..b95658bf74 100644 --- a/src/bin/list/main.rs +++ b/src/bin/list/main.rs @@ -74,12 +74,12 @@ impl Args { fn handle_list(args: &Args) -> Result> { if args.flag_tree { - let manifest = try!(Manifest::open_lock_file(&args.flag_manifest_path + let manifest = Manifest::open_lock_file(&args.flag_manifest_path .as_ref() - .map(|s| &s[..]))); + .map(|s| &s[..]))?; list_tree(&manifest) } else { - let manifest = try!(Manifest::open(&args.flag_manifest_path.as_ref().map(|s| &s[..]))); + let manifest = Manifest::open(&args.flag_manifest_path.as_ref().map(|s| &s[..]))?; list_section(&manifest, args.get_section()).or_else(|err| match err { ListError::SectionMissing(..) => Ok("".into()), _ => Err(err), diff --git a/src/bin/list/tree.rs b/src/bin/list/tree.rs index ca107586bc..f69e332162 100644 --- a/src/bin/list/tree.rs +++ b/src/bin/list/tree.rs @@ -29,9 +29,9 @@ fn parse_dep_from_str(input: &str) -> Option { } fn get_root_deps(lock_file: &toml::value::Table) -> Result, ListError> { - let root_deps = try!(lock_file.get("root") + let root_deps = lock_file.get("root") .and_then(|field| field.get("dependencies").to_owned()) - .ok_or_else(|| ListError::SectionMissing("dependencies".to_owned()))); + .ok_or_else(|| ListError::SectionMissing("dependencies".to_owned()))?; Ok(root_deps.as_array() .into_iter() @@ -47,20 +47,20 @@ fn get_root_deps(lock_file: &toml::value::Table) -> Result, List } fn get_packages(lock_file: &toml::value::Table) -> Result { - let packages: &toml::Value = try!(lock_file.get("package").ok_or(ListError::PackagesMissing)); + let packages: &toml::Value = lock_file.get("package").ok_or(ListError::PackagesMissing)?; let mut output = BTreeMap::new(); for pkg in packages.as_array().into_iter().flat_map(|p| p.iter()) { - let package = try!(pkg.as_table().ok_or(ListError::PackageInvalid)); + let package = pkg.as_table().ok_or(ListError::PackageInvalid)?; - let name = try!(package.get("name") + let name = package.get("name") .and_then(|item| item.as_str()) - .ok_or(ListError::PackageFieldMissing("name"))); + .ok_or(ListError::PackageFieldMissing("name"))?; - let version = try!(package.get("version") + let version = package.get("version") .and_then(|item| item.as_str()) - .ok_or(ListError::PackageFieldMissing("version"))); + .ok_or(ListError::PackageFieldMissing("version"))?; let deps: Dependencies = package.get("dependencies") .and_then(|item| { @@ -106,7 +106,7 @@ fn list_deps_helper(pkgs: &Packages, if let Some(subdeps) = pkgs.get(dep) { levels.push(is_last); - let sublist = try!(list_deps_helper(pkgs, subdeps, levels)); + let sublist = list_deps_helper(pkgs, subdeps, levels)?; output.push_str(&sublist); levels.pop(); } @@ -122,8 +122,8 @@ fn list_deps(pkgs: &Packages, deps: &[Dependency]) -> Result pub fn parse_lock_file(manifest: &Manifest) -> Result { let lock_file = &manifest.data; - let root_deps = try!(get_root_deps(lock_file)); - let pkgs = try!(get_packages(lock_file)); + let root_deps = get_root_deps(lock_file)?; + let pkgs = get_packages(lock_file)?; list_deps(&pkgs, &root_deps) } diff --git a/src/bin/rm/main.rs b/src/bin/rm/main.rs index 46a35b40a5..0796e9f062 100644 --- a/src/bin/rm/main.rs +++ b/src/bin/rm/main.rs @@ -38,14 +38,14 @@ Remove a dependency to a Cargo.toml manifest file. "; fn handle_rm(args: &Args) -> Result<(), Box> { - let mut manifest = try!(Manifest::open(&args.flag_manifest_path.as_ref().map(|s| &s[..]))); + let mut manifest = Manifest::open(&args.flag_manifest_path.as_ref().map(|s| &s[..]))?; manifest.remove_from_table(args.get_section(), args.arg_crate.as_ref()) .map_err(From::from) .and_then(|_| { - let mut file = try!(Manifest::find_file(&args.flag_manifest_path + let mut file = Manifest::find_file(&args.flag_manifest_path .as_ref() - .map(|s| &s[..]))); + .map(|s| &s[..]))?; manifest.write_to_file(&mut file) }) } diff --git a/src/manifest.rs b/src/manifest.rs index a1dbd5ae05..c1d03ca81c 100644 --- a/src/manifest.rs +++ b/src/manifest.rs @@ -63,7 +63,7 @@ fn find(specified: &Option<&str>, file: CargoFile) -> Result let file_path = specified.map(PathBuf::from); if let Some(path) = file_path { - if try!(fs::metadata(&path)).is_file() { + if fs::metadata(&path)?.is_file() { Ok(path) } else { search(&path, file).map_err(From::from) @@ -118,18 +118,18 @@ impl Manifest { /// Open the `Cargo.toml` for a path (or the process' `cwd`) pub fn open(path: &Option<&str>) -> Result> { - let mut file = try!(Manifest::find_file(path)); + let mut file = Manifest::find_file(path)?; let mut data = String::new(); - try!(file.read_to_string(&mut data)); + file.read_to_string(&mut data)?; data.parse() } /// Open the `Cargo.lock` for a path (or the process' `cwd`) pub fn open_lock_file(path: &Option<&str>) -> Result> { - let mut file = try!(Manifest::find_lock_file(path)); + let mut file = Manifest::find_lock_file(path)?; let mut data = String::new(); - try!(file.read_to_string(&mut data)); + file.read_to_string(&mut data)?; data.parse() } @@ -138,13 +138,13 @@ impl Manifest { pub fn write_to_file(&self, file: &mut File) -> Result<(), Box> { let mut toml = self.data.clone(); - let (proj_header, proj_data) = try!(toml.remove("package") + let (proj_header, proj_data) = toml.remove("package") .map(|data| ("package", data)) .or_else(|| { toml.remove("project") .map(|data| ("project", data)) }) - .ok_or(ManifestError::MissingManifest)); + .ok_or(ManifestError::MissingManifest)?; let new_contents = format!("[{}]\n{}{}", proj_header, @@ -154,7 +154,7 @@ impl Manifest { // We need to truncate the file, otherwise the new contents // will be mixed up with the old ones. - try!(file.set_len(new_contents_bytes.len() as u64)); + file.set_len(new_contents_bytes.len() as u64)?; file.write_all(new_contents_bytes).map_err(From::from) }