From 2382146dcae1a36c0f42f20f496c78178cf9d50b Mon Sep 17 00:00:00 2001 From: Blake Mealey Date: Tue, 9 Nov 2021 17:44:07 -0600 Subject: [PATCH] removed unnecessary mod and unused function --- src/commands/deploy.rs | 2 +- src/logger.rs | 223 +++++++++++++++++++---------------------- src/resources.rs | 2 +- src/state.rs | 2 +- 4 files changed, 107 insertions(+), 122 deletions(-) diff --git a/src/commands/deploy.rs b/src/commands/deploy.rs index 633341e..597294c 100644 --- a/src/commands/deploy.rs +++ b/src/commands/deploy.rs @@ -8,7 +8,7 @@ use yansi::Paint; use crate::{ config::{load_config_file, Config, DeploymentConfig}, - logger::logger, + logger, resource_manager::RobloxResourceManager, resources::{EvaluateResults, ResourceGraph, ResourceManager}, state::{get_desired_graph, get_previous_state, save_state, ResourceState}, diff --git a/src/logger.rs b/src/logger.rs index 4829806..134d076 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -1,134 +1,119 @@ -pub mod logger { - use std::{ - fmt::Display, - panic, - sync::atomic::{AtomicU16, Ordering}, - }; +use std::{ + fmt::Display, + panic, + sync::atomic::{AtomicU16, Ordering}, +}; - use difference::{Changeset, Difference}; - use yansi::{Color, Paint, Style}; +use difference::{Changeset, Difference}; +use yansi::{Color, Paint, Style}; - static ACTION_COUNT: AtomicU16 = AtomicU16::new(0); +static ACTION_COUNT: AtomicU16 = AtomicU16::new(0); - fn with_prefix_and_style(text: S1, prefix: S2, style: Style) -> String - where - S1: Display, - S2: Display, - { - text.to_string() - .split('\n') - .map(|line| { - format!( - "{}{}", - prefix.to_string(), - Paint::new(line).with_style(style) - ) - }) - .collect::>() - .join("\n") - .to_owned() - } +fn with_prefix_and_style(text: S1, prefix: S2, style: Style) -> String +where + S1: Display, + S2: Display, +{ + text.to_string() + .split('\n') + .map(|line| { + format!( + "{}{}", + prefix.to_string(), + Paint::new(line).with_style(style) + ) + }) + .collect::>() + .join("\n") + .to_owned() +} - fn with_prefix(text: S1, prefix: S2) -> String - where - S1: Display, - S2: Display, - { - with_prefix_and_style(text, prefix, Style::default()) - } +fn with_prefix(text: S1, prefix: S2) -> String +where + S1: Display, + S2: Display, +{ + with_prefix_and_style(text, prefix, Style::default()) +} - fn get_line_prefix() -> String { - format!( - "{}", - " │ ".repeat(ACTION_COUNT.load(Ordering::SeqCst).into()) - ) - } +fn get_line_prefix() -> String { + format!( + "{}", + " │ ".repeat(ACTION_COUNT.load(Ordering::SeqCst).into()) + ) +} - pub fn log(message: S) - where - S: Display, - { - let line_prefix = get_line_prefix(); - println!("{}", with_prefix(&message, &line_prefix)); - } +pub fn log(message: S) +where + S: Display, +{ + let line_prefix = get_line_prefix(); + println!("{}", with_prefix(&message, &line_prefix)); +} - pub fn log_error(message: S) - where - S: Display, - { - let line_prefix = get_line_prefix(); - println!( - "{}", - with_prefix_and_style(&message, &line_prefix, Style::new(Color::Red)) - ); - } +pub fn start_action(title: S) +where + S: Display, +{ + log(title); + log(" ╷"); + ACTION_COUNT.fetch_add(1, Ordering::SeqCst); +} - pub fn start_action(title: S) - where - S: Display, - { - log(title); - log(" ╷"); - ACTION_COUNT.fetch_add(1, Ordering::SeqCst); +fn end_action_internal(message: S1, results: Option) +where + S1: Display, + S2: Display, +{ + if ACTION_COUNT.load(Ordering::SeqCst) == 0 { + panic!("Attempted to end an action that was not started."); } - fn end_action_internal(message: S1, results: Option) - where - S1: Display, - S2: Display, - { - if ACTION_COUNT.load(Ordering::SeqCst) == 0 { - panic!("Attempted to end an action that was not started."); - } - - log(""); - ACTION_COUNT.fetch_sub(1, Ordering::SeqCst); - log(&format!(" ╰─ {}", message)); - if let Some(results) = results { - log(&with_prefix_and_style( - results, - " ", - Style::default().dimmed(), - )); - } - log(""); + log(""); + ACTION_COUNT.fetch_sub(1, Ordering::SeqCst); + log(&format!(" ╰─ {}", message)); + if let Some(results) = results { + log(&with_prefix_and_style( + results, + " ", + Style::default().dimmed(), + )); } + log(""); +} - pub fn end_action(message: S) - where - S: Display, - { - end_action_internal(message, None::); - } +pub fn end_action(message: S) +where + S: Display, +{ + end_action_internal(message, None::); +} - pub fn end_action_with_results(message: S1, results: S2) - where - S1: Display, - S2: Display, - { - end_action_internal(message, Some(results)); - } +pub fn end_action_with_results(message: S1, results: S2) +where + S1: Display, + S2: Display, +{ + end_action_internal(message, Some(results)); +} - pub fn log_changeset(changeset: Changeset) { - log(&changeset - .diffs - .iter() - .map(|diff| match diff { - Difference::Same(same) => { - with_prefix_and_style(same, " ", Style::default().dimmed()) - } - Difference::Add(add) => with_prefix_and_style( - add, - &format!("{} ", Paint::green("+")), - Style::new(Color::Green), - ), - Difference::Rem(rem) => with_prefix_and_style( - rem, - &format!("{} ", Paint::red("-")), - Style::new(Color::Red), - ), - }) - .collect::>() - .join(&changeset.split)); - } +pub fn log_changeset(changeset: Changeset) { + log(&changeset + .diffs + .iter() + .map(|diff| match diff { + Difference::Same(same) => with_prefix_and_style(same, " ", Style::default().dimmed()), + Difference::Add(add) => with_prefix_and_style( + add, + &format!("{} ", Paint::green("+")), + Style::new(Color::Green), + ), + Difference::Rem(rem) => with_prefix_and_style( + rem, + &format!("{} ", Paint::red("-")), + Style::new(Color::Red), + ), + }) + .collect::>() + .join(&changeset.split)); } diff --git a/src/resources.rs b/src/resources.rs index 2ffa239..a0162e4 100644 --- a/src/resources.rs +++ b/src/resources.rs @@ -4,7 +4,7 @@ use difference::Changeset; use serde::{Deserialize, Serialize}; use yansi::Paint; -use crate::logger::logger; +use crate::logger; #[derive(Serialize, Deserialize, Clone)] #[serde(rename_all = "camelCase")] diff --git a/src/state.rs b/src/state.rs index e923dda..3a103ec 100644 --- a/src/state.rs +++ b/src/state.rs @@ -11,7 +11,7 @@ use tokio::io::AsyncReadExt; use crate::{ config::{Config, DeploymentConfig, PlayabilityConfig, RemoteStateConfig, StateConfig}, - logger::logger, + logger, resource_manager::{resource_types, AssetId, SINGLETON_RESOURCE_ID}, resources::{InputRef, Resource, ResourceGraph}, roblox_api::{ExperienceConfigurationModel, PlaceConfigurationModel},