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

ref data into data II/V #118

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
58 changes: 29 additions & 29 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use clap::{ArgMatches, Clap, FromArgMatches};

use crate as deploy;

use self::deploy::{DeployFlake, ParseFlakeError};
use self::deploy::{data, settings};
use futures_util::stream::{StreamExt, TryStreamExt};
use log::{debug, error, info, warn};
use serde::Serialize;
Expand Down Expand Up @@ -168,9 +168,9 @@ pub enum GetDeploymentDataError {
/// Evaluates the Nix in the given `repo` and return the processed Data from it
async fn get_deployment_data(
supports_flakes: bool,
flakes: &[deploy::DeployFlake<'_>],
flakes: &[data::DeployFlake<'_>],
extra_build_args: &[String],
) -> Result<Vec<deploy::data::Data>, GetDeploymentDataError> {
) -> Result<Vec<settings::Root>, GetDeploymentDataError> {
futures_util::stream::iter(flakes).then(|flake| async move {

info!("Evaluating flake in {}", flake.repo);
Expand Down Expand Up @@ -272,9 +272,9 @@ struct PromptPart<'a> {

fn print_deployment(
parts: &[(
&deploy::DeployFlake<'_>,
deploy::DeployData,
deploy::DeployDefs,
&data::DeployFlake<'_>,
data::DeployData,
data::DeployDefs,
)],
) -> Result<(), toml::ser::Error> {
let mut part_map: HashMap<String, HashMap<String, PromptPart>> = HashMap::new();
Expand Down Expand Up @@ -315,9 +315,9 @@ pub enum PromptDeploymentError {

fn prompt_deployment(
parts: &[(
&deploy::DeployFlake<'_>,
deploy::DeployData,
deploy::DeployDefs,
&data::DeployFlake<'_>,
data::DeployData,
data::DeployDefs,
)],
) -> Result<(), PromptDeploymentError> {
print_deployment(parts)?;
Expand Down Expand Up @@ -378,7 +378,7 @@ pub enum RunDeployError {
#[error("Profile was provided without a node name")]
ProfileWithoutNode,
#[error("Error processing deployment definitions: {0}")]
DeployDataDefs(#[from] deploy::DeployDataDefsError),
InvalidDeployDataDefs(#[from] data::DeployDataDefsError),
#[error("Failed to make printable TOML of deployment: {0}")]
TomlFormat(#[from] toml::ser::Error),
#[error("{0}")]
Expand All @@ -388,19 +388,19 @@ pub enum RunDeployError {
}

type ToDeploy<'a> = Vec<(
&'a deploy::DeployFlake<'a>,
&'a deploy::data::Data,
(&'a str, &'a deploy::data::Node),
(&'a str, &'a deploy::data::Profile),
&'a data::DeployFlake<'a>,
&'a settings::Root,
(&'a str, &'a settings::Node),
(&'a str, &'a settings::Profile),
)>;

async fn run_deploy(
deploy_flakes: Vec<deploy::DeployFlake<'_>>,
data: Vec<deploy::data::Data>,
deploy_flakes: Vec<data::DeployFlake<'_>>,
data: Vec<settings::Root>,
supports_flakes: bool,
check_sigs: bool,
interactive: bool,
cmd_overrides: &deploy::CmdOverrides,
cmd_overrides: &data::CmdOverrides,
keep_result: bool,
result_path: Option<&str>,
extra_build_args: &[String],
Expand Down Expand Up @@ -437,7 +437,7 @@ async fn run_deploy(
None => return Err(RunDeployError::NodeNotFound(node_name.clone())),
};

let mut profiles_list: Vec<(&str, &deploy::data::Profile)> = Vec::new();
let mut profiles_list: Vec<(&str, &settings::Profile)> = Vec::new();

for profile_name in [
node.node_settings.profiles_order.iter().collect(),
Expand Down Expand Up @@ -466,7 +466,7 @@ async fn run_deploy(
let mut l = Vec::new();

for (node_name, node) in &data.nodes {
let mut profiles_list: Vec<(&str, &deploy::data::Profile)> = Vec::new();
let mut profiles_list: Vec<(&str, &settings::Profile)> = Vec::new();

for profile_name in [
node.node_settings.profiles_order.iter().collect(),
Expand Down Expand Up @@ -508,13 +508,13 @@ async fn run_deploy(
.collect();

let mut parts: Vec<(
&deploy::DeployFlake<'_>,
deploy::DeployData,
deploy::DeployDefs,
&data::DeployFlake<'_>,
data::DeployData,
data::DeployDefs,
)> = Vec::new();

for (deploy_flake, data, (node_name, node), (profile_name, profile)) in to_deploy {
let deploy_data = deploy::make_deploy_data(
let deploy_data = data::make_deploy_data(
&data.generic_settings,
node,
node_name,
Expand Down Expand Up @@ -550,7 +550,7 @@ async fn run_deploy(
.await?;
}

let mut succeeded: Vec<(&deploy::DeployData, &deploy::DeployDefs)> = vec![];
let mut succeeded: Vec<(&data::DeployData, &data::DeployDefs)> = vec![];

// Run all deployments
// In case of an error rollback any previoulsy made deployment.
Expand Down Expand Up @@ -595,7 +595,7 @@ pub enum RunError {
#[error("Failed to evaluate deployment data: {0}")]
GetDeploymentData(#[from] GetDeploymentDataError),
#[error("Error parsing flake: {0}")]
ParseFlake(#[from] deploy::ParseFlakeError),
ParseFlake(#[from] data::ParseFlakeError),
#[error("Error initiating logger: {0}")]
Logger(#[from] flexi_logger::FlexiLoggerError),
#[error("{0}")]
Expand All @@ -619,12 +619,12 @@ pub async fn run(args: Option<&ArgMatches>) -> Result<(), RunError> {
.targets
.unwrap_or_else(|| vec![opts.clone().target.unwrap_or_else(|| ".".to_string())]);

let deploy_flakes: Vec<DeployFlake> = deploys
let deploy_flakes: Vec<data::DeployFlake> = deploys
.iter()
.map(|f| deploy::parse_flake(f.as_str()))
.collect::<Result<Vec<DeployFlake>, ParseFlakeError>>()?;
.map(|f| data::parse_flake(f.as_str()))
.collect::<Result<Vec<data::DeployFlake>, data::ParseFlakeError>>()?;

let cmd_overrides = deploy::CmdOverrides {
let cmd_overrides = data::CmdOverrides {
ssh_user: opts.ssh_user,
profile_user: opts.profile_user,
ssh_opts: opts.ssh_opts,
Expand Down
Loading