Skip to content

Commit

Permalink
Update configuration reporting with work and break time (#189)
Browse files Browse the repository at this point in the history
* Update reporting

* Update
  • Loading branch information
TheRustyPickle committed May 3, 2023
1 parent 16c0687 commit 2ebb2b9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,16 @@ pub enum ConfigurationError {
JsonError(SerdeJsonError),
SlackConfigNotFound,
DiscordConfigNotFound,
UnspecifiedWorkTime,
UnspecifiedBreakTime,
LoadFail(io::Error),
// config json wrong format?
}

impl fmt::Display for ConfigurationError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ConfigurationError::FileNotFound => write!(f, "can not find configuration file "),
ConfigurationError::FileNotFound => write!(f, "can not find configuration file"),
ConfigurationError::FileOpenError(_) => write!(f, "failed to open the file"),
ConfigurationError::JsonError(_) => write!(f, "failed to deserialize json"),
ConfigurationError::SlackConfigNotFound => {
Expand All @@ -84,6 +86,8 @@ impl fmt::Display for ConfigurationError {
ConfigurationError::DiscordConfigNotFound => {
write!(f, "can not find discord config in json")
}
ConfigurationError::UnspecifiedWorkTime => write!(f, "not specified"),
ConfigurationError::UnspecifiedBreakTime => write!(f, "not specified"),
ConfigurationError::LoadFail(e) => write!(f, "failed to load: {}", e),
}
}
Expand All @@ -97,6 +101,8 @@ impl std::error::Error for ConfigurationError {
ConfigurationError::JsonError(ref e) => Some(e),
ConfigurationError::SlackConfigNotFound => None,
ConfigurationError::DiscordConfigNotFound => None,
ConfigurationError::UnspecifiedWorkTime => None,
ConfigurationError::UnspecifiedBreakTime => None,
ConfigurationError::LoadFail(ref e) => Some(e),
}
}
Expand Down
16 changes: 15 additions & 1 deletion src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn generate_configuration_report(
.update_reason(&ConfigurationError::SlackConfigNotFound),
};

let slack_token_message = match config.get_slack_channel() {
let slack_token_message = match config.get_slack_token() {
Some(_) => Report::new("O", "slack_token"),
None => {
Report::new("X", "slack_token").update_reason(&ConfigurationError::SlackConfigNotFound)
Expand All @@ -62,11 +62,25 @@ pub fn generate_configuration_report(
.update_reason(&ConfigurationError::DiscordConfigNotFound),
};

let work_time_default_value_message = match config.get_work_time() {
Some(_) => Report::new("O", "default_work_time"),
None => Report::new("X", "default_work_time")
.update_reason(&ConfigurationError::UnspecifiedWorkTime),
};

let break_time_default_value_message = match config.get_break_time() {
Some(_) => Report::new("O", "default_break_time"),
None => Report::new("X", "default_break_time")
.update_reason(&ConfigurationError::UnspecifiedBreakTime),
};

Table::new(vec![
config_err_message,
slack_channel_message,
slack_token_message,
discord_webhook_url_message,
work_time_default_value_message,
break_time_default_value_message,
])
.with(Style::modern())
.to_string()
Expand Down

0 comments on commit 2ebb2b9

Please sign in to comment.