diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d232e4e..04e8558 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,9 +14,6 @@ jobs: with: fetch-depth: 1 - - name: Build - run: cargo build --release --locked - - name: Install stable toolchain uses: actions-rs/toolchain@v1 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index ee3c15f..1a3302f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +## 0.2.0 + +#### Fixes +* Fixed handling of errors in main function +* Response will no longer have unnecessary '\n' appended at the end + +#### Features +* Bearer auth available with --bearer (-B) command +* Specifying 'get' as method is no longer required - it is the default + +#### Tests +* Added cli tests running the mock server, the command and checking the output + + ## 0.1.0 #### First, unstable release diff --git a/Cargo.lock b/Cargo.lock index 81a70ac..18c9446 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9,6 +9,168 @@ dependencies = [ "memchr", ] +[[package]] +name = "arrayref" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" + +[[package]] +name = "arrayvec" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" + +[[package]] +name = "ascii-canvas" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff8eb72df928aafb99fe5d37b383f2fe25bd2a765e3e5f7c365916b6f2463a29" +dependencies = [ + "term", +] + +[[package]] +name = "assert-json-diff" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4259cbe96513d2f1073027a259fc2ca917feb3026a5a8d984e3628e490255cc0" +dependencies = [ + "extend", + "serde", + "serde_json", +] + +[[package]] +name = "assert_cmd" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dc1679af9a1ab4bea16f228b05d18f8363f8327b1fa8db00d2760cfafc6b61e" +dependencies = [ + "doc-comment", + "predicates", + "predicates-core", + "predicates-tree", + "wait-timeout", +] + +[[package]] +name = "async-channel" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59740d83946db6a5af71ae25ddf9562c2b176b2ca42cf99a455f09f4a220d6b9" +dependencies = [ + "concurrent-queue", + "event-listener", + "futures-core", +] + +[[package]] +name = "async-executor" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb877970c7b440ead138f6321a3b5395d6061183af779340b65e20c0fede9146" +dependencies = [ + "async-task", + "concurrent-queue", + "fastrand", + "futures-lite", + "once_cell", + "vec-arena", +] + +[[package]] +name = "async-global-executor" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73079b49cd26b8fd5a15f68fc7707fc78698dc2a3d61430f2a7a9430230dfa04" +dependencies = [ + "async-executor", + "async-io", + "futures-lite", + "num_cpus", + "once_cell", +] + +[[package]] +name = "async-io" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9315f8f07556761c3e48fec2e6b276004acf426e6dc068b2c2251854d65ee0fd" +dependencies = [ + "concurrent-queue", + "fastrand", + "futures-lite", + "libc", + "log", + "nb-connect", + "once_cell", + "parking", + "polling", + "vec-arena", + "waker-fn", + "winapi 0.3.9", +] + +[[package]] +name = "async-mutex" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479db852db25d9dbf6204e6cb6253698f175c15726470f78af0d918e99d6156e" +dependencies = [ + "event-listener", +] + +[[package]] +name = "async-std" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7e82538bc65a25dbdff70e4c5439d52f068048ab97cdea0acd73f131594caa1" +dependencies = [ + "async-global-executor", + "async-io", + "async-mutex", + "blocking", + "crossbeam-utils", + "futures-channel", + "futures-core", + "futures-io", + "futures-lite", + "gloo-timers", + "kv-log-macro", + "log", + "memchr", + "num_cpus", + "once_cell", + "pin-project-lite 0.1.11", + "pin-utils", + "slab", + "wasm-bindgen-futures", +] + +[[package]] +name = "async-task" +version = "4.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91831deabf0d6d7ec49552e489aed63b7456a7a3c46cff62adad428110b0af0" + +[[package]] +name = "async-trait" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d3a45e77e34375a7923b1e8febb049bb011f064714a8e17a1a616fef01da13d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "atomic-waker" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" + [[package]] name = "atty" version = "0.2.14" @@ -32,24 +194,114 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +[[package]] +name = "basic-cookies" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb53b6b315f924c7f113b162e53b3901c05fc9966baf84d201dfcc7432a4bb38" +dependencies = [ + "lalrpop", + "lalrpop-util", + "regex", +] + +[[package]] +name = "bit-set" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e11e16035ea35e4e5997b393eacbf6f63983188f7a2ad25bfb13465f5ad59de" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f0dc55f2d8a1a85650ac47858bb001b4c0dd73d79e3c455a842925e68d29cd3" + [[package]] name = "bitflags" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +[[package]] +name = "blake2b_simd" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587" +dependencies = [ + "arrayref", + "arrayvec", + "constant_time_eq", +] + +[[package]] +name = "block-buffer" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" +dependencies = [ + "block-padding", + "byte-tools", + "byteorder", + "generic-array", +] + +[[package]] +name = "block-padding" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" +dependencies = [ + "byte-tools", +] + +[[package]] +name = "blocking" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5e170dbede1f740736619b776d7251cb1b9095c435c34d8ca9f57fcd2f335e9" +dependencies = [ + "async-channel", + "async-task", + "atomic-waker", + "fastrand", + "futures-lite", + "once_cell", +] + [[package]] name = "bumpalo" version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" +[[package]] +name = "byte-tools" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" + +[[package]] +name = "byteorder" +version = "1.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" + [[package]] name = "bytes" version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" +[[package]] +name = "cache-padded" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba" + [[package]] name = "cc" version = "1.0.65" @@ -80,7 +332,7 @@ dependencies = [ "indexmap", "lazy_static", "os_str_bytes", - "strsim", + "strsim 0.10.0", "termcolor", "textwrap", "unicode-width", @@ -111,6 +363,15 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "concurrent-queue" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30ed07550be01594c6026cff2a1d7fe9c8f683caa798e12b68694ac9e88286a3" +dependencies = [ + "cache-padded", +] + [[package]] name = "console_error_panic_hook" version = "0.1.6" @@ -121,6 +382,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + [[package]] name = "core-foundation" version = "0.9.1" @@ -137,18 +404,119 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" +[[package]] +name = "crossbeam-utils" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02d96d1e189ef58269ebe5b97953da3274d83a93af647c2ddd6f9dab28cedb8d" +dependencies = [ + "autocfg", + "cfg-if 1.0.0", + "lazy_static", +] + +[[package]] +name = "curl" +version = "0.4.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e268162af1a5fe89917ae25ba3b0a77c8da752bdc58e7dbb4f15b91fbd33756e" +dependencies = [ + "curl-sys", + "libc", + "openssl-probe", + "openssl-sys", + "schannel", + "socket2", + "winapi 0.3.9", +] + +[[package]] +name = "curl-sys" +version = "0.4.38+curl-7.73.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "498ecfb4f59997fd40023d62a9f1e506e768b2baeb59a1d311eb9751cdcd7e3f" +dependencies = [ + "cc", + "libc", + "libnghttp2-sys", + "libz-sys", + "openssl-sys", + "pkg-config", + "vcpkg", + "winapi 0.3.9", +] + +[[package]] +name = "diff" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499" + [[package]] name = "difference" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" +[[package]] +name = "digest" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +dependencies = [ + "generic-array", +] + +[[package]] +name = "dirs" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901" +dependencies = [ + "libc", + "redox_users", + "winapi 0.3.9", +] + +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + +[[package]] +name = "docopt" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f525a586d310c87df72ebcd98009e57f1cc030c8c268305287a476beb653969" +dependencies = [ + "lazy_static", + "regex", + "serde", + "strsim 0.9.3", +] + [[package]] name = "downcast" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4bb454f0228b18c7f4c3b0ebbee346ed9c52e7443b0999cd543ff3571205701d" +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + +[[package]] +name = "ena" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7402b94a93c24e742487327a7cd839dc9d36fec9de9fb25b09f2dae459f36c3" +dependencies = [ + "log", +] + [[package]] name = "encoding_rs" version = "0.8.26" @@ -158,6 +526,45 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "event-listener" +version = "2.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59" + +[[package]] +name = "extend" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f47da3a72ec598d9c8937a7ebca8962a5c7a1f28444e38c2b33c771ba3f55f05" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "fake-simd" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" + +[[package]] +name = "fastrand" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca5faf057445ce5c9d4329e382b2ce7ca38550ef3b73a5348362d5f24e0c7fe3" +dependencies = [ + "instant", +] + +[[package]] +name = "fixedbitset" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d" + [[package]] name = "float-cmp" version = "0.8.0" @@ -167,6 +574,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "flume" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bebadab126f8120d410b677ed95eee4ba6eb7c6dd8e34a5ec88a08050e26132" +dependencies = [ + "futures-core", + "futures-sink", + "spinning_top", +] + [[package]] name = "fnv" version = "1.0.7" @@ -241,6 +659,33 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "611834ce18aaa1bd13c4b374f5d653e1027cf99b6b502584ff8c9a64413b30bb" +[[package]] +name = "futures-lite" +version = "1.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e6c079abfac3ab269e2927ec048dabc89d009ebfdda6b8ee86624f30c689658" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite 0.1.11", + "waker-fn", +] + +[[package]] +name = "futures-macro" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77408a692f1f97bcc61dc001d752e00643408fbc922e4d634c655df50d595556" +dependencies = [ + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "futures-sink" version = "0.3.8" @@ -264,13 +709,25 @@ checksum = "d304cff4a7b99cfb7986f7d43fbe93d175e72e704a8860787cc95e9ffd85cbd2" dependencies = [ "futures-core", "futures-io", + "futures-macro", "futures-task", "memchr", "pin-project 1.0.2", "pin-utils", + "proc-macro-hack", + "proc-macro-nested", "slab", ] +[[package]] +name = "generic-array" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" +dependencies = [ + "typenum", +] + [[package]] name = "getrandom" version = "0.1.15" @@ -282,6 +739,19 @@ dependencies = [ "wasi", ] +[[package]] +name = "gloo-timers" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47204a46aaff920a1ea58b11d03dec6f704287d27561724a4631e450654a891f" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "h2" version = "0.2.7" @@ -359,6 +829,33 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" +[[package]] +name = "httpmock" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1e098238acaa95e0bb3fd357317817fde35efb9cdedf74b18b24698499eea9d" +dependencies = [ + "assert-json-diff", + "async-trait", + "base64", + "basic-cookies", + "crossbeam-utils", + "difference", + "futures-util", + "hyper", + "isahc", + "lazy_static", + "levenshtein", + "log", + "puddle", + "qstring", + "regex", + "serde", + "serde_json", + "serde_regex", + "tokio", +] + [[package]] name = "hyper" version = "0.13.9" @@ -417,6 +914,15 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "instant" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" +dependencies = [ + "cfg-if 1.0.0", +] + [[package]] name = "iovec" version = "0.1.4" @@ -432,6 +938,40 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47be2f14c678be2fdcab04ab1171db51b2762ce6f0a8ee87c8dd4a04ed216135" +[[package]] +name = "isahc" +version = "0.9.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80aafab09693e9fa74b76ef207c55dc1cba5d9d5dc6dcc1b6a96d008a98000e9" +dependencies = [ + "bytes", + "crossbeam-utils", + "curl", + "curl-sys", + "encoding_rs", + "flume", + "futures-lite", + "http", + "log", + "mime", + "once_cell", + "slab", + "sluice", + "tracing", + "tracing-futures", + "url", + "waker-fn", +] + +[[package]] +name = "itertools" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "0.4.6" @@ -440,9 +980,9 @@ checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" [[package]] name = "js-sys" -version = "0.3.45" +version = "0.3.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca059e81d9486668f12d455a4ea6daa600bd408134cd17e3d3fb5a32d1f016f8" +checksum = "cf3d7383929f7c9c7c2d0fa596f325832df98c3704f2c60553080f7127a58175" dependencies = [ "wasm-bindgen", ] @@ -457,18 +997,95 @@ dependencies = [ "winapi-build", ] +[[package]] +name = "kv-log-macro" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" +dependencies = [ + "log", +] + +[[package]] +name = "lalrpop" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60fb56191fb8ed5311597e5750debe6779c9fdb487dbaa5ff302592897d7a2c8" +dependencies = [ + "ascii-canvas", + "atty", + "bit-set", + "diff", + "docopt", + "ena", + "itertools", + "lalrpop-util", + "petgraph", + "regex", + "regex-syntax", + "serde", + "serde_derive", + "sha2", + "string_cache", + "term", + "unicode-xid", +] + +[[package]] +name = "lalrpop-util" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6771161eff561647fad8bb7e745e002c304864fb8f436b52b30acda51fca4408" + [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "levenshtein" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66189c12161c65c0023ceb53e2fccc0013311bcb36a7cbd0f9c5e938b408ac96" + [[package]] name = "libc" version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614" +[[package]] +name = "libnghttp2-sys" +version = "0.1.5+1.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9657455ff47889b70ffd37c3e118e8cdd23fd1f9f3293a285f141070621c4c79" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "libz-sys" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "602113192b08db8f38796c4e85c39e960c145965140e918018bcde1952429655" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "lock_api" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd96ffd135b2fd7b973ac026d28085defbe8983df057ced3eb4f2130b0831312" +dependencies = [ + "scopeguard", +] + [[package]] name = "log" version = "0.4.11" @@ -508,9 +1125,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.6.22" +version = "0.6.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fce347092656428bc8eaf6201042cb551b8d67855af7374542a92a0fbfcac430" +checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" dependencies = [ "cfg-if 0.1.10", "fuchsia-zircon", @@ -582,6 +1199,16 @@ dependencies = [ "tempfile", ] +[[package]] +name = "nb-connect" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8123a81538e457d44b933a02faf885d3fe8408806b23fa700e8f01c6c3a98998" +dependencies = [ + "libc", + "winapi 0.3.9", +] + [[package]] name = "net2" version = "0.2.36" @@ -593,6 +1220,12 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "new_debug_unreachable" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" + [[package]] name = "normalize-line-endings" version = "0.3.0" @@ -624,6 +1257,12 @@ version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" +[[package]] +name = "opaque-debug" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" + [[package]] name = "openssl" version = "0.10.30" @@ -663,12 +1302,37 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "afb2e1c3ee07430c2cf76151675e583e0f19985fa6efae47d6848a3e2c824f85" +[[package]] +name = "parking" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" + [[package]] name = "percent-encoding" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +[[package]] +name = "petgraph" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "467d164a6de56270bd7c4d070df81d07beace25012d5103ced4e9ff08d6afdb7" +dependencies = [ + "fixedbitset", + "indexmap", +] + +[[package]] +name = "phf_shared" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c00cf8b9eafe68dde5e9eaa2cef8ee84a9336a47d566ec55ca16589633b65af7" +dependencies = [ + "siphasher", +] + [[package]] name = "pin-project" version = "0.4.27" @@ -733,12 +1397,31 @@ version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" +[[package]] +name = "polling" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2a7bc6b2a29e632e45451c941832803a18cce6781db04de8a04696cdca8bde4" +dependencies = [ + "cfg-if 0.1.10", + "libc", + "log", + "wepoll-sys", + "winapi 0.3.9", +] + [[package]] name = "ppv-lite86" version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + [[package]] name = "predicates" version = "1.0.5" @@ -792,6 +1475,18 @@ dependencies = [ "version_check", ] +[[package]] +name = "proc-macro-hack" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" + +[[package]] +name = "proc-macro-nested" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a" + [[package]] name = "proc-macro2" version = "1.0.24" @@ -801,6 +1496,24 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "puddle" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cf84452e80b28e2b05e53964d6f5a44a57978ce19b4920be49e1a61079a24d7" +dependencies = [ + "async-std", +] + +[[package]] +name = "qstring" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d464fae65fff2680baf48019211ce37aaec0c78e9264c84a3e484717f965104e" +dependencies = [ + "percent-encoding", +] + [[package]] name = "quote" version = "1.0.7" @@ -812,11 +1525,14 @@ dependencies = [ [[package]] name = "qurl" -version = "0.1.0" +version = "0.2.0" dependencies = [ + "assert_cmd", "clap", "colored", + "httpmock", "mockall", + "predicates", "reqwest", "rstest", "tokio", @@ -869,6 +1585,17 @@ version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" +[[package]] +name = "redox_users" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" +dependencies = [ + "getrandom", + "redox_syscall", + "rust-argon2", +] + [[package]] name = "regex" version = "1.4.2" @@ -946,6 +1673,18 @@ dependencies = [ "syn", ] +[[package]] +name = "rust-argon2" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b18820d944b33caa75a71378964ac46f58517c92b6ae5f762636247c09e78fb" +dependencies = [ + "base64", + "blake2b_simd", + "constant_time_eq", + "crossbeam-utils", +] + [[package]] name = "rustc_version" version = "0.2.3" @@ -977,6 +1716,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + [[package]] name = "security-framework" version = "2.0.0" @@ -1020,6 +1765,20 @@ name = "serde" version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b88fa983de7720629c9387e9f517353ed404164b1e482c970a90c1a4aaf7dc1a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbd1ae72adb44aab48f325a02444a5fc079349a8d804c1fc922aed3f7454c74e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] name = "serde_json" @@ -1032,6 +1791,16 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_regex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8136f1a4ea815d7eac4101cfd0b16dc0cb5e1fe1b8609dfd728058656b7badf" +dependencies = [ + "regex", + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.0" @@ -1044,12 +1813,41 @@ dependencies = [ "serde", ] +[[package]] +name = "sha2" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a256f46ea78a0c0d9ff00077504903ac881a1dafdc20da66545699e7776b3e69" +dependencies = [ + "block-buffer", + "digest", + "fake-simd", + "opaque-debug", +] + +[[package]] +name = "siphasher" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa8f3741c7372e75519bd9346068370c9cdaabcc1f9599cbcf2a2719352286b7" + [[package]] name = "slab" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" +[[package]] +name = "sluice" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e24ed1edc8e774f2ec098b0650eec82bfc7c59ddd16cd0e17797bdc92ce2bf1" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", +] + [[package]] name = "socket2" version = "0.3.17" @@ -1062,6 +1860,34 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "spinning_top" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e529d73e80d64b5f2631f9035113347c578a1c9c7774b83a2b880788459ab36" +dependencies = [ + "lock_api", +] + +[[package]] +name = "string_cache" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ddb1139b5353f96e429e1a5e19fbaf663bddedaa06d1dbd49f82e352601209a" +dependencies = [ + "lazy_static", + "new_debug_unreachable", + "phf_shared", + "precomputed-hash", + "serde", +] + +[[package]] +name = "strsim" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" + [[package]] name = "strsim" version = "0.10.0" @@ -1070,9 +1896,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.52" +version = "1.0.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c1e438504729046a5cfae47f97c30d6d083c7d91d94603efdae3477fc070d4c" +checksum = "8833e20724c24de12bbaba5ad230ea61c3eafb05b881c7c9d3cfe8638b187e68" dependencies = [ "proc-macro2", "quote", @@ -1093,6 +1919,17 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "term" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edd106a334b7657c10b7c540a0106114feadeb4dc314513e97df481d5d966f42" +dependencies = [ + "byteorder", + "dirs", + "winapi 0.3.9", +] + [[package]] name = "termcolor" version = "1.1.2" @@ -1204,9 +2041,21 @@ dependencies = [ "cfg-if 1.0.0", "log", "pin-project-lite 0.2.0", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80e0ccfc3378da0cce270c946b676a376943f5cd16aeba64568e7939806f4ada" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "tracing-core" version = "0.1.17" @@ -1238,6 +2087,12 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" +[[package]] +name = "typenum" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" + [[package]] name = "unicase" version = "2.6.0" @@ -1301,6 +2156,12 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c" +[[package]] +name = "vec-arena" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eafc1b9b2dfc6f5529177b62cf806484db55b32dc7c9658a118e11bbeb33061d" + [[package]] name = "vec_map" version = "0.8.2" @@ -1313,6 +2174,21 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" +[[package]] +name = "wait-timeout" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +dependencies = [ + "libc", +] + +[[package]] +name = "waker-fn" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" + [[package]] name = "want" version = "0.3.0" @@ -1331,11 +2207,11 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasm-bindgen" -version = "0.2.68" +version = "0.2.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ac64ead5ea5f05873d7c12b545865ca2b8d28adfc50a49b84770a3a97265d42" +checksum = "3cd364751395ca0f68cafb17666eee36b63077fb5ecd972bbcd74c90c4bf736e" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "serde", "serde_json", "wasm-bindgen-macro", @@ -1343,9 +2219,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.68" +version = "0.2.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f22b422e2a757c35a73774860af8e112bff612ce6cb604224e8e47641a9e4f68" +checksum = "1114f89ab1f4106e5b55e688b828c0ab0ea593a1ea7c094b141b14cbaaec2d62" dependencies = [ "bumpalo", "lazy_static", @@ -1358,11 +2234,11 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.18" +version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7866cab0aa01de1edf8b5d7936938a7e397ee50ce24119aef3e1eaa3b6171da" +checksum = "1fe9756085a84584ee9457a002b7cdfe0bfff169f45d2591d8be1345a6780e35" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "js-sys", "wasm-bindgen", "web-sys", @@ -1370,9 +2246,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.68" +version = "0.2.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b13312a745c08c469f0b292dd2fcd6411dba5f7160f593da6ef69b64e407038" +checksum = "7a6ac8995ead1f084a8dea1e65f194d0973800c7f571f6edd70adf06ecf77084" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1380,9 +2256,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.68" +version = "0.2.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f249f06ef7ee334cc3b8ff031bfc11ec99d00f34d86da7498396dc1e3b1498fe" +checksum = "b5a48c72f299d80557c7c62e37e7225369ecc0c963964059509fbafe917c7549" dependencies = [ "proc-macro2", "quote", @@ -1393,15 +2269,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.68" +version = "0.2.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d649a3145108d7d3fbcde896a468d1bd636791823c9921135218ad89be08307" +checksum = "7e7811dd7f9398f14cc76efd356f98f03aa30419dea46aa810d71e819fc97158" [[package]] name = "wasm-bindgen-test" -version = "0.3.18" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34d1cdc8b98a557f24733d50a1199c4b0635e465eecba9c45b214544da197f64" +checksum = "0355fa0c1f9b792a09b6dcb6a8be24d51e71e6d74972f9eb4a44c4c004d24a25" dependencies = [ "console_error_panic_hook", "js-sys", @@ -1413,9 +2289,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-test-macro" -version = "0.3.18" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8fb9c67be7439ee8ab1b7db502a49c05e51e2835b66796c705134d9b8e1a585" +checksum = "27e07b46b98024c2ba2f9e83a10c2ef0515f057f2da299c1762a2017de80438b" dependencies = [ "proc-macro2", "quote", @@ -1423,14 +2299,23 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.45" +version = "0.3.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bf6ef87ad7ae8008e15a355ce696bed26012b7caa21605188cfd8214ab51e2d" +checksum = "222b1ef9334f92a21d3fb53dc3fd80f30836959a90f9274a626d7e06315ba3c3" dependencies = [ "js-sys", "wasm-bindgen", ] +[[package]] +name = "wepoll-sys" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fcb14dea929042224824779fbc82d9fab8d2e6d3cbc0ac404de8edf489e77ff" +dependencies = [ + "cc", +] + [[package]] name = "winapi" version = "0.2.8" diff --git a/Cargo.toml b/Cargo.toml index 32ac815..2e3cb31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "qurl" -version = "0.1.0" +version = "0.2.0" authors = ["Radosław Stępień "] edition = "2018" description = "Quick command-line HTTP request utility written in Rust" @@ -19,4 +19,7 @@ colored = "2" [dev-dependencies] rstest = "0.6" -mockall = "0.8.0" +mockall = "0.8" +assert_cmd = "1.0" +predicates = "1" +httpmock = "0.5" diff --git a/README.md b/README.md index 05484fb..ded83f7 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,13 @@ You can also head over to [releases tab](https://github.com/Zeerooth/qurl/releas Simplest GET request: +```bash +$ qurl https://httpbin.org/get +``` + + +Or, with explicit method parameter: + ```bash $ qurl get https://httpbin.org/get ``` @@ -38,14 +45,14 @@ $ qurl get https://httpbin.org/get To enable verbose output and get more information about requests and responses, add ``-v`` flag (which will from now on be used in examples to provide some better understading about what's going on under the hood): ```bash -$ qurl get https://httpbin.org/get -v +$ qurl https://httpbin.org/get -v ``` Let's add some headers (note that headers are **not** case-sensitive): ```bash -$ qurl get https://httpbin.org/get -v --header accept:application/json +$ qurl https://httpbin.org/get -v --header accept:application/json ``` diff --git a/src/cli.rs b/src/cli.rs index 996877f..4ae3d7a 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,11 +1,8 @@ -use clap::{App, Arg, ArgMatches}; +use clap::{App, Arg, ArgMatches, crate_version}; use crate::types::{ - auth::BasicAuth, - data::Body, - data::Json, - multipart::Headers, - multipart::FormData, - multipart::QueryString, + auth::{BasicAuth, BearerAuth}, + data::{Body, Json}, + multipart::{Headers, FormData, QueryString}, proxy::Proxy, redirect::RedirectPolicy, timeout::Timeout, @@ -15,12 +12,15 @@ use crate::types::ProvidesCLIArguments; pub fn app_matches() -> ArgMatches { App::new("qURL") .about("Quick command-line HTTP request utility written in Rust") + .setting(clap::AppSettings::AllowMissingPositional) + .version(crate_version!()) .arg( Arg::new("method") .about("HTTP request method") .index(1) .possible_values(&["get", "post", "put", "head", "patch", "delete"]) - .required(true) + .required(false) + .default_value("get") ) .arg( Arg::new("url") @@ -36,11 +36,12 @@ pub fn app_matches() -> ArgMatches { .required(false) ) .args(Headers::provide_arguments()) - .args(FormData::provide_arguments()) + .args(QueryString::provide_arguments()) .args(BasicAuth::provide_arguments()) + .args(BearerAuth::provide_arguments()) .args(Body::provide_arguments()) .args(Json::provide_arguments()) - .args(QueryString::provide_arguments()) + .args(FormData::provide_arguments()) .args(Proxy::provide_arguments()) .args(RedirectPolicy::provide_arguments()) .args(Timeout::provide_arguments()) diff --git a/src/lib.rs b/src/lib.rs index 561e717..27060c1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,12 +1,14 @@ -use reqwest::Response; -use reqwest::{Client, ClientBuilder, Request}; -use types::auth::{BasicAuth}; -use types::data::{Json, Body}; -use types::proxy::Proxy; -use types::multipart::{Headers, FormData, QueryString}; -use types::redirect::RedirectPolicy; -use types::timeout::Timeout; -use types::{ConfiguresBuilder, ConfiguresClient}; +use reqwest::{Response, Client, ClientBuilder, Request}; +use types::{ + auth::{BasicAuth, BearerAuth}, + data::{Body, Json}, + multipart::{Headers, FormData, QueryString}, + proxy::Proxy, + redirect::RedirectPolicy, + timeout::Timeout, + ConfiguresClient, + ConfiguresBuilder +}; use clap::{ArgMatches}; use error::{ParsingError, ErrorWrapper}; use std::fmt::Display; @@ -55,6 +57,7 @@ impl RequestParser { None => return Err(ParsingError::new("No method provided").into()) }; req_builder = BasicAuth::build(req_builder, matches)?; + req_builder = BearerAuth::build(req_builder, matches)?; req_builder = Body::build(req_builder, matches)?; req_builder = Json::build(req_builder, matches)?; req_builder = Headers::build(req_builder, matches)?; @@ -67,7 +70,7 @@ impl RequestParser { pub async fn send(self) -> Result { match self.client.execute(self.request).await { Ok(response) => Ok(response), - Err(err) => Err(format!("Error sending request: {}", err)) + Err(err) => Err(format!("{}", err)) } } } diff --git a/src/main.rs b/src/main.rs index 5ee48b0..189907a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,19 +5,27 @@ use colored::*; #[tokio::main] async fn main() -> Result<(), Box> { + std::process::exit(match run_app().await { + Ok(_) => 0, + Err(err) => { + eprintln!("{} {}", "error:".bright_red(), err); + 1 + } + }); + +} + +async fn run_app() -> Result<(), Box> { let matches = app_matches(); let verbose = matches.is_present("verbose"); let built_request = match RequestParser::new(matches) { Ok(req_parser) => req_parser, - Err(err) => { - eprintln!("{} {}", "error:".bright_red(), err.inner()); - std::process::exit(1) - } + Err(err) => return Err(err.inner()) }; if verbose { println!("{}\n{}", "Making a request:".green().bold(), built_request.prettify()?); } let response = built_request.send().await?; if verbose { println!("{}\n{}", "Received response:".green().bold(), response.prettify().unwrap()); } - println!("{}", response.text().await?); - if verbose { println!("{}", "Program finished successfully".green().bold()); } + print!("{}", response.text().await?); // TODO: make sure to handle timeout of body transfer! + if verbose { println!("{}", "\nProgram finished successfully".green().bold()); } Ok(()) } \ No newline at end of file diff --git a/src/types/auth.rs b/src/types/auth.rs index fec051d..59df920 100644 --- a/src/types/auth.rs +++ b/src/types/auth.rs @@ -36,3 +36,34 @@ impl ProvidesCLIArguments for BasicAuth { ] } } + +pub struct BearerAuth; +static BEARER_ARG: &str = "bearer"; + +impl<'a> ConfiguresBuilder<'a, &'a str, &'a str> for BearerAuth { + fn modify_builder(request_builder: RequestBuilder, value: &'a str) -> Result { + Ok(request_builder.bearer_auth(value)) + } + + fn get_value(matches: &'a ArgMatches) -> Option<&str> { + matches.value_of(BEARER_ARG) + } + + fn process_value(value: &'a str) -> Result<&'a str, ErrorWrapper> { + Ok(value) + } +} + +impl ProvidesCLIArguments for BearerAuth { + fn provide_arguments() -> Vec> { + vec![ + Arg::new(BEARER_ARG) + .about("OAuth 2.0 Bearer Token") + .takes_value(true) + .short('B') + .long(BEARER_ARG) + .required(false) + ] + } +} + diff --git a/src/types/redirect.rs b/src/types/redirect.rs index 7902ad8..c7cc07c 100644 --- a/src/types/redirect.rs +++ b/src/types/redirect.rs @@ -5,6 +5,7 @@ use crate::error::{ErrorWrapper, ParsingError}; use clap::{Arg, ArgMatches}; pub struct RedirectPolicy; +static REDIRECT_ARG: &str = "max-redirects"; impl<'a> ConfiguresClient<'a, &'a str, Policy> for RedirectPolicy { fn modify_client(client_builder: ClientBuilder, value: Policy) -> Result { @@ -12,7 +13,7 @@ impl<'a> ConfiguresClient<'a, &'a str, Policy> for RedirectPolicy { } fn get_value(matches: &'a ArgMatches) -> Option<&str> { - matches.value_of("max-redirects") + matches.value_of(REDIRECT_ARG) } fn process_value(value: &str) -> Result { @@ -27,11 +28,11 @@ impl<'a> ConfiguresClient<'a, &'a str, Policy> for RedirectPolicy { impl ProvidesCLIArguments for RedirectPolicy { fn provide_arguments() -> Vec> { vec![ - Arg::new("max-redirects") - .about("Set the maximum number of redirects the program will follow (defaults to 10)") + Arg::new(REDIRECT_ARG) + .about("Set the maximum number of redirects the program will follow [default: 10]") .takes_value(true) .short('r') - .long("max-redirects") + .long(REDIRECT_ARG) .required(false) ] } diff --git a/tests/cli.rs b/tests/cli.rs new file mode 100644 index 0000000..84027b3 --- /dev/null +++ b/tests/cli.rs @@ -0,0 +1,137 @@ +use assert_cmd::{Command}; +use predicates::{prelude::*}; +use httpmock::{MockServer}; +use httpmock::Method; +use rstest::*; +use std::fs; + +fn test_json_response() -> String { + fs::read_to_string("tests/resources/mock.json").expect("reading mock json failed") +} + +fn mock_server_port() -> u16 { + let server = MockServer::start(); + server.mock(|when, then| { + when.method(Method::GET) + .path("/get"); + then.status(200).header("Content-Type", "application/json").body(test_json_response()); + }); + server.mock(|when, then| { + when.method(Method::POST) + .path("/post") + .header("Authorization", "Basic dXNlcm5hbWU6cGFzc3dvcmQ="); + then.status(200).header("Content-Type", "text/html").body("success"); + }); + server.mock(|when, then| { + when.method(Method::PUT) + .path("/put") + .header("Authorization", "Bearer AaBbCcDdEeFfGg0987654321fFeEdDcCbBaA"); + then.status(200).header("Content-Type", "text/html").body("success"); + }); + server.mock(|when, then|{ + when.path("/redirect"); + then.temporary_redirect(format!("/redirect2")); + }); + server.mock(|when, then|{ + when.path("/redirect2"); + then.status(200).header("Content-Type", "text/html").body("success"); + }); + server.port() +} + +#[rstest(args, success, text, + case( + vec![ + format!("http://127.0.0.1:{}/get", mock_server_port()), + String::from("-v") + ], + true, + predicate::str::contains("HTTP/1.1 200 OK") + ), + case( + vec![ + format!("http://127.0.0.1:{}/get", mock_server_port()), + String::from("-v") + ], + true, + predicate::str::contains(format!("{}\n {}", "content-type: application/json", "content-length: 74")) + ), + case( + vec![ + format!("http://127.0.0.1:{}/get", mock_server_port()) + ], + true, + predicate::str::similar(test_json_response()) + ), + case( + vec![ + format!("http://127.0.0.1:{}/get", mock_server_port()), + String::from("--query"), + String::from("key=value"), + String::from("--query"), + String::from("key2=value2"), + String::from("-v") + ], + true, + predicate::str::is_match(r"Final URL: http://127.0.0.1:\d+/get\?key=value&key2=value2")? + ), + case( + vec![ + String::from("post"), + format!("http://127.0.0.1:{}/post", mock_server_port()), + String::from("--basic-auth"), + String::from("username:password"), + ], + true, + predicate::str::similar("success") + ), + case( + vec![ + String::from("put"), + format!("http://127.0.0.1:{}/put", mock_server_port()), + String::from("--bearer"), + String::from("AaBbCcDdEeFfGg0987654321fFeEdDcCbBaA"), + ], + true, + predicate::str::similar("success") + ), + case( + vec![ + format!("http://127.0.0.1:{}/redirect", mock_server_port()), + String::from("--max-redirects"), + String::from("1") + ], + false, + predicate::str::contains("too many redirects") + ), + case( + vec![ + String::from("get"), + format!("http://127.0.0.1:{}/redirect", mock_server_port()), + String::from("--max-redirects"), + String::from("2"), + String::from("-v"), + ], + true, + predicate::str::is_match(r"Final URL: http://127.0.0.1:\d+/redirect2")? + ), + case( + vec![ + String::from("get"), + format!("http://127.0.0.1:{}/get", mock_server_port()), + String::from("--timeout"), + String::from("0"), + String::from("-v") + ], + false, + predicate::str::contains("operation timed out") + ), +)] +fn test_commands>(args: Vec, success: bool, text: T) -> Result<(), Box> { + let cmd = Command::cargo_bin("qurl").unwrap().args(args).assert(); + match success { + true => cmd.success().stdout(text), + false => cmd.failure().stderr(text) + }; + Ok(()) +} \ No newline at end of file diff --git a/tests/parsers.rs b/tests/parsers.rs index 9e3b953..bc6666d 100644 --- a/tests/parsers.rs +++ b/tests/parsers.rs @@ -4,6 +4,7 @@ use rstest::*; #[rstest(argument, delimiter, expected, case("header_name:header_value", ":", Ok(("header_name", "header_value"))), + case("key-value-more-delimiters", "-", Ok(("key", "value-more-delimiters"))), case("key:value", "=", Err(error::ParsingError::new("'key:value' must be delimited by '='"))) )] fn test_delimiter_parser(argument: &str, delimiter: &str, expected: Result<(&str, &str), error::ParsingError>) { diff --git a/tests/resources/mock.json b/tests/resources/mock.json new file mode 100644 index 0000000..8a9b1f7 --- /dev/null +++ b/tests/resources/mock.json @@ -0,0 +1,5 @@ +{ + "resource_type": "json", + "server": "127.0.0.1", + "count": 6 +} \ No newline at end of file