Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoverbear committed Sep 18, 2023
1 parent bfa0765 commit deefad2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 49 deletions.
90 changes: 42 additions & 48 deletions src/action/common/place_nix_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,56 +39,50 @@ impl PlaceNixConfiguration {
let mut extra_conf_text = vec![];
for extra in extra_conf {
let buf = match &extra {
UrlOrPathOrString::Url(url) => {
match url.scheme() {
"https" | "http" => {
let mut buildable_client = reqwest::Client::builder();
if let Some(proxy) = &proxy {
buildable_client = buildable_client.proxy(
reqwest::Proxy::all(proxy.clone())
.map_err(ActionErrorKind::Reqwest)
.map_err(Self::error)?,
)
}
if let Some(ssl_cert_file) = &ssl_cert_file {
let ssl_cert =
parse_ssl_cert(ssl_cert_file).await.map_err(Self::error)?;
buildable_client = buildable_client.add_root_certificate(ssl_cert);
}
let client = buildable_client
.build()
.map_err(ActionErrorKind::Reqwest)
.map_err(Self::error)?;
let req = client
.get(url.clone())
.build()
.map_err(ActionErrorKind::Reqwest)
.map_err(Self::error)?;
let res = client
.execute(req)
.await
.map_err(ActionErrorKind::Reqwest)
.map_err(Self::error)?;
res.text()
.await
.map_err(ActionErrorKind::Reqwest)
.map_err(Self::error)?
},
"file" => {
tokio::fs::read_to_string(url.path())
.await
.map_err(|e| ActionErrorKind::Read(PathBuf::from(url.path()), e))
.map_err(Self::error)?
},
_ => return Err(Self::error(ActionErrorKind::UnknownUrlScheme)),
}
},
UrlOrPathOrString::Path(path) => {
tokio::fs::read_to_string(path)
UrlOrPathOrString::Url(url) => match url.scheme() {
"https" | "http" => {
let mut buildable_client = reqwest::Client::builder();
if let Some(proxy) = &proxy {
buildable_client = buildable_client.proxy(
reqwest::Proxy::all(proxy.clone())
.map_err(ActionErrorKind::Reqwest)
.map_err(Self::error)?,
)
}
if let Some(ssl_cert_file) = &ssl_cert_file {
let ssl_cert =
parse_ssl_cert(ssl_cert_file).await.map_err(Self::error)?;
buildable_client = buildable_client.add_root_certificate(ssl_cert);
}
let client = buildable_client
.build()
.map_err(ActionErrorKind::Reqwest)
.map_err(Self::error)?;
let req = client
.get(url.clone())
.build()
.map_err(ActionErrorKind::Reqwest)
.map_err(Self::error)?;
let res = client
.execute(req)
.await
.map_err(ActionErrorKind::Reqwest)
.map_err(Self::error)?;
res.text()
.await
.map_err(ActionErrorKind::Reqwest)
.map_err(Self::error)?
},
"file" => tokio::fs::read_to_string(url.path())
.await
.map_err(|e| ActionErrorKind::Read(PathBuf::from(path), e))
.map_err(Self::error)?
.map_err(|e| ActionErrorKind::Read(PathBuf::from(url.path()), e))
.map_err(Self::error)?,
_ => return Err(Self::error(ActionErrorKind::UnknownUrlScheme)),
},
UrlOrPathOrString::Path(path) => tokio::fs::read_to_string(path)
.await
.map_err(|e| ActionErrorKind::Read(PathBuf::from(path), e))
.map_err(Self::error)?,
UrlOrPathOrString::String(string) => string.clone(),
};
extra_conf_text.push(buf)
Expand Down
5 changes: 4 additions & 1 deletion src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
use std::{collections::HashMap, fmt::Display, path::PathBuf, str::FromStr};

#[cfg(feature = "cli")]
use clap::{ArgAction, error::{ContextKind, ContextValue}};
use clap::{
error::{ContextKind, ContextValue},
ArgAction,
};
use url::Url;

pub const SCRATCH_DIR: &str = "/nix/temp-install-dir";
Expand Down

0 comments on commit deefad2

Please sign in to comment.