From 390aea67228a64a4daf9ffaeda100007966f0ef3 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Wed, 11 Aug 2021 14:55:39 -0500 Subject: [PATCH] Refactor merge DeployDefs into DeployData (single view) --- src/cli.rs | 2 +- src/data.rs | 28 ++++++++++++++-------------- src/deploy.rs | 6 +++--- src/push.rs | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 44252b9c..ac70dfec 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -168,7 +168,7 @@ pub enum RunDeployError { ResolveTarget(#[from] data::ResolveTargetError), #[error("Error processing deployment definitions: {0}")] - DeployDataDefs(#[from] data::DeployDataDefsError), + DeployDataError(#[from] data::DeployDataError), #[error("Failed to make printable TOML of deployment: {0}")] TomlFormat(#[from] toml::ser::Error), #[error("{0}")] diff --git a/src/data.rs b/src/data.rs index 404ce55e..fb9b80be 100644 --- a/src/data.rs +++ b/src/data.rs @@ -265,6 +265,14 @@ pub struct DeployData<'a> { pub merged_settings: settings::GenericSettings, } +#[derive(Error, Debug)] +pub enum DeployDataError { + #[error("Neither `user` nor `sshUser` are set for profile {0} of node {1}")] + NoProfileUser(String, String), + #[error("Value `hostname` is not define for profile {0} of node {1}")] + NoProfileHost(String, String), +} + #[derive(Clap, Debug, Clone)] pub struct Flags { /// Check signatures when using `nix copy` @@ -310,14 +318,6 @@ pub struct DeployDefs { pub sudo: Option, } -#[derive(Error, Debug)] -pub enum DeployDataDefsError { - #[error("Neither `user` nor `sshUser` are set for profile {0} of node {1}")] - NoProfileUser(String, String), - #[error("Value `hostname` is not define for profile {0} of node {1}")] - NoProfileHost(String, String), -} - impl<'a> DeployData<'a> { fn new( @@ -352,7 +352,7 @@ impl<'a> DeployData<'a> { } } - pub fn defs(&'a self) -> Result { + pub fn defs(&'a self) -> Result { let ssh_user = match self.merged_settings.ssh_user { Some(ref u) => u.clone(), None => whoami::username(), @@ -375,7 +375,7 @@ impl<'a> DeployData<'a> { }) } - pub fn ssh_uri(&'a self) -> Result { + pub fn ssh_uri(&'a self) -> Result { let hostname = match self.hostname { Some(x) => x, @@ -390,7 +390,7 @@ impl<'a> DeployData<'a> { } // can be dropped once ssh fully supports ipv6 uris - pub fn ssh_non_uri(&'a self) -> Result { + pub fn ssh_non_uri(&'a self) -> Result { let hostname = match self.hostname { Some(x) => x, @@ -408,7 +408,7 @@ impl<'a> DeployData<'a> { self.merged_settings.ssh_opts.iter() } - pub fn get_profile_path(&'a self) -> Result { + pub fn get_profile_path(&'a self) -> Result { let profile_user = self.get_profile_user()?; let profile_path = match self.profile.profile_settings.profile_path { None => match &profile_user[..] { @@ -423,13 +423,13 @@ impl<'a> DeployData<'a> { Ok(profile_path) } - pub fn get_profile_user(&'a self) -> Result { + pub fn get_profile_user(&'a self) -> Result { let profile_user = match self.merged_settings.user { Some(ref x) => x.clone(), None => match self.merged_settings.ssh_user { Some(ref x) => x.clone(), None => { - return Err(DeployDataDefsError::NoProfileUser( + return Err(DeployDataError::NoProfileUser( self.profile_name.to_owned(), self.node_name.to_owned(), )) diff --git a/src/deploy.rs b/src/deploy.rs index 46bb4e25..27386816 100644 --- a/src/deploy.rs +++ b/src/deploy.rs @@ -206,7 +206,7 @@ pub enum ConfirmProfileError { SSHConfirmExitError(Option), #[error("Deployment data invalid: {0}")] - InvalidDeployDataDefsError(#[from] data::DeployDataDefsError), + InvalidDeployDataError(#[from] data::DeployDataError), } pub async fn confirm_profile( @@ -265,7 +265,7 @@ pub enum DeployProfileError { ConfirmError(#[from] ConfirmProfileError), #[error("Deployment data invalid: {0}")] - InvalidDeployDataDefsError(#[from] data::DeployDataDefsError), + InvalidDeployDataError(#[from] data::DeployDataError), } pub async fn deploy_profile( @@ -404,7 +404,7 @@ pub enum RevokeProfileError { SSHRevokeExitError(Option), #[error("Deployment data invalid: {0}")] - InvalidDeployDataDefsError(#[from] data::DeployDataDefsError), + InvalidDeployDataError(#[from] data::DeployDataError), } pub async fn revoke( deploy_data: &data::DeployData<'_>, diff --git a/src/push.rs b/src/push.rs index bf9df700..59457e81 100644 --- a/src/push.rs +++ b/src/push.rs @@ -45,7 +45,7 @@ pub enum PushProfileError { CopyExitError(Option), #[error("Deployment data invalid: {0}")] - InvalidDeployDataDefsError(#[from] data::DeployDataDefsError), + InvalidDeployDataError(#[from] data::DeployDataError), } pub struct PushProfileData<'a> {