Skip to content

Commit

Permalink
removed unnecessary mod and unused function
Browse files Browse the repository at this point in the history
  • Loading branch information
blake-mealey committed Nov 9, 2021
1 parent c6549f6 commit 2382146
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 122 deletions.
2 changes: 1 addition & 1 deletion src/commands/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
223 changes: 104 additions & 119 deletions src/logger.rs
Original file line number Diff line number Diff line change
@@ -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<S1, S2>(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::<Vec<_>>()
.join("\n")
.to_owned()
}
fn with_prefix_and_style<S1, S2>(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::<Vec<_>>()
.join("\n")
.to_owned()
}

fn with_prefix<S1, S2>(text: S1, prefix: S2) -> String
where
S1: Display,
S2: Display,
{
with_prefix_and_style(text, prefix, Style::default())
}
fn with_prefix<S1, S2>(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<S>(message: S)
where
S: Display,
{
let line_prefix = get_line_prefix();
println!("{}", with_prefix(&message, &line_prefix));
}
pub fn log<S>(message: S)
where
S: Display,
{
let line_prefix = get_line_prefix();
println!("{}", with_prefix(&message, &line_prefix));
}

pub fn log_error<S>(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<S>(title: S)
where
S: Display,
{
log(title);
log(" ╷");
ACTION_COUNT.fetch_add(1, Ordering::SeqCst);
}

pub fn start_action<S>(title: S)
where
S: Display,
{
log(title);
log(" ╷");
ACTION_COUNT.fetch_add(1, Ordering::SeqCst);
fn end_action_internal<S1, S2>(message: S1, results: Option<S2>)
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<S1, S2>(message: S1, results: Option<S2>)
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<S>(message: S)
where
S: Display,
{
end_action_internal(message, None::<String>);
}
pub fn end_action<S>(message: S)
where
S: Display,
{
end_action_internal(message, None::<String>);
}

pub fn end_action_with_results<S1, S2>(message: S1, results: S2)
where
S1: Display,
S2: Display,
{
end_action_internal(message, Some(results));
}
pub fn end_action_with_results<S1, S2>(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::<Vec<String>>()
.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::<Vec<String>>()
.join(&changeset.split));
}
2 changes: 1 addition & 1 deletion src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
2 changes: 1 addition & 1 deletion src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit 2382146

Please sign in to comment.