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

Update configuration reporting with work and break time #189

Merged
merged 2 commits into from
May 3, 2023
Merged
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
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() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!!!

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
Loading