From: Stephen Seo Date: Fri, 7 Jan 2022 07:05:37 +0000 (+0900) Subject: Differentiate between log level/state, bump version X-Git-Tag: 0.2.9 X-Git-Url: https://git.seodisparate.com/stephenseo/LD54_Box_Survival?a=commitdiff_plain;h=231db343385b1080998ac3a8e12dd6b7020f49ad;p=mpd_info_screen Differentiate between log level/state, bump version --- diff --git a/Cargo.lock b/Cargo.lock index 3cef8d0..38f9046 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1427,7 +1427,7 @@ dependencies = [ [[package]] name = "mpd_info_screen" -version = "0.2.8" +version = "0.2.9" dependencies = [ "ggez", "image", diff --git a/Cargo.toml b/Cargo.toml index 0e6fc00..970e913 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mpd_info_screen" -version = "0.2.8" +version = "0.2.9" edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/README.md b/README.md index bdb3d88..ae80447 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ counter, and the filename currently being played # Usage - mpd_info_screen 0.2.8 + mpd_info_screen 0.2.9 USAGE: mpd_info_screen [FLAGS] [OPTIONS] [port] diff --git a/src/debug_log.rs b/src/debug_log.rs index 90b7200..9778cf4 100644 --- a/src/debug_log.rs +++ b/src/debug_log.rs @@ -1,9 +1,17 @@ use std::fmt::Display; use structopt::clap::arg_enum; +#[derive(Copy, Clone, Debug, PartialEq)] +pub enum LogState { + ERROR, + WARNING, + DEBUG, + VERBOSE, +} + arg_enum! { #[derive(Copy, Clone, Debug, PartialEq)] - pub enum LogState { + pub enum LogLevel { ERROR, WARNING, DEBUG, @@ -11,22 +19,22 @@ arg_enum! { } } -pub fn log(msg: T, level: LogState, state: LogState) +pub fn log(msg: T, state: LogState, level: LogLevel) where T: Display, { - if level == LogState::ERROR { + if state == LogState::ERROR { log_error(msg); - } else if level == LogState::WARNING { - if state != LogState::ERROR { + } else if state == LogState::WARNING { + if level != LogLevel::ERROR { log_warning(msg); } - } else if level == LogState::DEBUG { - if state == LogState::DEBUG || state == LogState::VERBOSE { + } else if state == LogState::DEBUG { + if level == LogLevel::DEBUG || level == LogLevel::VERBOSE { log_debug(msg); } - } else if level == LogState::VERBOSE { - if state == LogState::VERBOSE { + } else if state == LogState::VERBOSE { + if level == LogLevel::VERBOSE { log_verbose(msg); } } else { diff --git a/src/main.rs b/src/main.rs index 07dceaa..483183c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,11 +38,11 @@ pub struct Opt { #[structopt( short = "l", long = "log-level", - possible_values = &debug_log::LogState::variants(), + possible_values = &debug_log::LogLevel::variants(), default_value = "ERROR", case_insensitive = true, )] - log_level: debug_log::LogState, + log_level: debug_log::LogLevel, } fn main() -> Result<(), String> { diff --git a/src/mpd_handler.rs b/src/mpd_handler.rs index b475a6c..f35588a 100644 --- a/src/mpd_handler.rs +++ b/src/mpd_handler.rs @@ -1,4 +1,4 @@ -use crate::debug_log::{log, LogState}; +use crate::debug_log::{log, LogLevel, LogState}; use std::io::{self, Read, Write}; use std::net::{IpAddr, Ipv4Addr, SocketAddr, TcpStream}; use std::str::FromStr; @@ -65,7 +65,7 @@ pub struct MPDHandlerState { self_thread: Option>>>>, dirty_flag: Arc, pub stop_flag: Arc, - log_level: LogState, + log_level: LogLevel, } fn check_next_chars( @@ -228,7 +228,7 @@ impl MPDHandler { host: Ipv4Addr, port: u16, password: String, - log_level: LogState, + log_level: LogLevel, ) -> Result { let stream = TcpStream::connect_timeout( &SocketAddr::new(IpAddr::V4(host), port),