mirror of
https://github.com/starship/starship.git
synced 2026-06-23 02:05:51 +07:00
feat: make reqwest an optional dependency (#979)
This commit is contained in:
+19
-9
@@ -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>";
|
||||
|
||||
Reference in New Issue
Block a user