Add a prediction mode

This commit is contained in:
Campbell Alden 2023-07-14 18:09:47 +09:00
parent 6b300b3d0a
commit 98d5fbe232
2 changed files with 71 additions and 11 deletions

40
src/modes.rs Normal file
View file

@ -0,0 +1,40 @@
use clap::ValueEnum;
#[derive(ValueEnum, Debug, Copy, Clone, Eq, PartialEq)]
pub enum Modes {
/// Perform calculations by treating stdin as a stream of time pairs separated by newlines
TimeTable,
/// Perform live tracking of the user's time until an EOF character is received.
Live,
/// Predict a user's day end time (assuming a 9 hour work day) based on the user's start time
/// and the duration of a user's break.
Prediction,
}
impl Modes {
/// Determine whether or not the variant supports piped input vs being used as a CLI tool
/// directly by a human
pub fn supports_piped_input(&self) -> bool {
match self {
Modes::TimeTable => true,
Modes::Live => false,
Modes::Prediction => false,
}
}
}
impl Default for Modes {
fn default() -> Self {
Self::TimeTable
}
}
impl std::fmt::Display for Modes {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.to_possible_value()
.expect("no values are skipped")
.get_name()
.fmt(f)
}
}