Skip to content

Commit

Permalink
fmt: cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
nrdxp committed Dec 10, 2021
1 parent 0303aca commit 8899158
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 36 deletions.
38 changes: 18 additions & 20 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use clap::Parser;
use linked_hash_set::LinkedHashSet;
use merge::Merge;
use rnix::{types::*, SyntaxKind::*};
use thiserror::Error;
use std::net::{SocketAddr, ToSocketAddrs};
use thiserror::Error;

use crate::settings;

Expand Down Expand Up @@ -73,11 +73,7 @@ impl<'a> Target {
}
};
Ok({
let hostname_: Option<String> = if ip.is_some() {
ip
} else {
hostname
};
let hostname_: Option<String> = if ip.is_some() { ip } else { hostname };
let d = DeployData::new(
repo,
node.to_owned(),
Expand Down Expand Up @@ -182,7 +178,6 @@ impl std::str::FromStr for Target {
};
};


let mut node: Option<String> = None;
let mut profile: Option<String> = None;

Expand All @@ -197,7 +192,7 @@ impl std::str::FromStr for Target {
node: None,
profile: None,
ip, // NB: error if not none; catched on target resolve
})
});
}
};

Expand Down Expand Up @@ -291,9 +286,7 @@ fn test_deploy_target_from_str() {
);

assert_eq!(
"../examples/system#example"
.parse::<Target>()
.unwrap(),
"../examples/system#example".parse::<Target>().unwrap(),
Target {
repo: "../examples/system".to_string(),
node: Some("example".to_string()),
Expand Down Expand Up @@ -340,7 +333,6 @@ pub struct DeployData<'a> {
// over potentially a series of sockets to deploy
// to
// pub sockets: Vec<SocketAddr>,

pub ssh_user: String,
pub ssh_uri: String,
pub temp_path: String,
Expand Down Expand Up @@ -450,18 +442,24 @@ impl<'a> DeployData<'a> {
};
let hostname = match hostname {
Some(x) => x,
None => if let Some(x) = &node.node_settings.hostname {
x.to_string()
} else {
return Err(DeployDataError::NoHost(node_name));
},
None => {
if let Some(x) = &node.node_settings.hostname {
x.to_string()
} else {
return Err(DeployDataError::NoHost(node_name));
}
}
};
let maybe_iter = &mut hostname[..].to_socket_addrs();
let sockets: Vec<SocketAddr> = match maybe_iter {
Ok(x) => x.into_iter().collect(),
Err(err) => return Err(
DeployDataError::InvalidSockent(repo, hostname, err.to_string()),
),
Err(err) => {
return Err(DeployDataError::InvalidSockent(
repo,
hostname,
err.to_string(),
))
}
};
let ssh_uri = format!("ssh://{}@{}", &ssh_user, sockets.first().unwrap());

Expand Down
9 changes: 4 additions & 5 deletions src/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ pub struct SshCommand<'a> {
impl<'a> SshCommand<'a> {
pub fn from_data(d: &'a data::DeployData) -> Result<Self, data::DeployDataError> {
let opts = d.merged_settings.ssh_opts.as_ref();
Ok(SshCommand { ssh_uri: d.ssh_uri.as_ref(), opts })
Ok(SshCommand {
ssh_uri: d.ssh_uri.as_ref(),
opts,
})
}

fn build(&self) -> Command {
Expand Down Expand Up @@ -299,7 +302,6 @@ pub async fn confirm_profile(
ssh: SshCommand<'_>,
confirm: ConfirmCommand<'_>,
) -> Result<(), ConfirmProfileError> {

debug!("Entering confirm_profile function ...");

let mut ssh_confirm_cmd = ssh.build();
Expand Down Expand Up @@ -349,7 +351,6 @@ pub async fn deploy_profile(
wait: WaitCommand<'_>,
confirm: ConfirmCommand<'_>,
) -> Result<(), DeployProfileError> {

debug!("Entering deploy_profile function ...");

if !activate.dry_activate {
Expand Down Expand Up @@ -383,7 +384,6 @@ pub async fn deploy_profile(
info!("Success activating, done!");
}
} else {

let ssh_activate = ssh_activate_cmd
.arg(activate_cmd)
.spawn()
Expand Down Expand Up @@ -457,7 +457,6 @@ pub async fn revoke(
ssh: SshCommand<'_>,
revoke: RevokeCommand<'_>,
) -> Result<(), RevokeProfileError> {

debug!("Entering revoke function ...");

info!(
Expand Down
18 changes: 7 additions & 11 deletions src/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ impl<'a> CopyCommand<'a> {
fast_connection: d.merged_settings.fast_connection,
check_sigs: &d.flags.checksigs,
hostname: uri,
nix_ssh_opts: format!("{} -p {}",
d
.merged_settings
.ssh_opts
.iter()
.fold("".to_string(), |s, o| format!("{} {}", s, o)),
nix_ssh_opts: format!(
"{} -p {}",
d.merged_settings
.ssh_opts
.iter()
.fold("".to_string(), |s, o| format!("{} {}", s, o)),
port,
),
}
Expand Down Expand Up @@ -203,7 +203,6 @@ pub async fn push_profile(
sign: SignCommand<'_>,
copy: CopyCommand<'_>,
) -> Result<(), PushProfileError> {

debug!("Entering push_profil function ...");

let node_name = build.node_name;
Expand Down Expand Up @@ -240,10 +239,7 @@ pub async fn push_profile(

let mut build_cmd = build.build(*derivation_name, supports_flakes);

let build_cmd_handle = build_cmd
.output()
.await
.map_err(PushProfileError::Build)?;
let build_cmd_handle = build_cmd.output().await.map_err(PushProfileError::Build)?;

match build_cmd_handle.status.code() {
Some(0) => (),
Expand Down

0 comments on commit 8899158

Please sign in to comment.