Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make reqwest optional dep #979

Merged
merged 1 commit into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ is-it-maintained-open-issues = { repository = "starship/starship" }
maintenance = { status = "actively-developed" }

[features]
default = ["battery"]
default = ["battery", "http"]
http = ["reqwest"]

[dependencies]
clap = "2.33.0"
Expand Down Expand Up @@ -52,7 +53,7 @@ urlencoding = "1.0.0"
open = "1.3.4"
# OpenSSL causes problems when building a MUSL release. Opting to use native SSL implementation
# see: https://github.com/richfelker/musl-cross-make/issues/65#issuecomment-509790889
reqwest = { version = "0.10.4", default-features = false, features = ["blocking", "rustls-tls"] }
reqwest = { version = "0.10.4", default-features = false, optional = true, features = ["blocking", "rustls-tls"] }
unicode-width = "0.1.7"
textwrap = "0.11.0"
term_size = "0.3.1"
Expand Down
28 changes: 19 additions & 9 deletions src/bug_report.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -21,21 +22,30 @@ 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
);
}
}

#[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>";
Expand Down