feat: make reqwest an optional dependency (#979)

This commit is contained in:
Matan Kushner
2020-03-05 10:53:58 -05:00
committed by GitHub
parent 7f82dd66ed
commit d894ef5ad3
2 changed files with 22 additions and 11 deletions
+19 -9
View File
@@ -1,8 +1,9 @@
use crate::utils::exec_cmd;
use reqwest;
use std::fs;
use std::path::PathBuf;
#[cfg(feature = "http")]
const GIT_IO_BASE_URL: &str = "https://git.io/";
pub fn create() {
@@ -21,14 +22,7 @@ pub fn create() {
if open::that(&link).is_ok() {
print!("Take a look at your browser. A GitHub issue has been populated with your configuration")
} else {
let link = reqwest::blocking::Client::new()
.post(&format!("{}{}", GIT_IO_BASE_URL, "create"))
.form(&[("url", &link)])
.send()
.and_then(|response| response.text())
.map(|slug| format!("{}{}", GIT_IO_BASE_URL, slug))
.unwrap_or(link);
let link = shorten_link(&link).unwrap_or(link);
println!(
"Click this link to create a GitHub issue populated with your configuration:\n\n {}",
link
@@ -36,6 +30,22 @@ pub fn create() {
}
}
#[cfg(feature = "http")]
fn shorten_link(link: &str) -> Option<String> {
reqwest::blocking::Client::new()
.post(&format!("{}{}", GIT_IO_BASE_URL, "create"))
.form(&[("url", link)])
.send()
.and_then(|response| response.text())
.map(|slug| format!("{}{}", GIT_IO_BASE_URL, slug))
.ok()
}
#[cfg(not(feature = "http"))]
fn shorten_link(_url: &str) -> Option<String> {
None
}
const UNKNOWN_SHELL: &str = "<unknown shell>";
const UNKNOWN_TERMINAL: &str = "<unknown terminal>";
const UNKNOWN_VERSION: &str = "<unknown version>";