-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add check on stopping on different days than starting
- Loading branch information
Showing
3 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/// Parsing and printing from and to cli. | ||
use std::str::FromStr; | ||
|
||
use crate::errors::*; | ||
|
||
#[derive(Debug)] | ||
pub enum YesNo { | ||
Yes, | ||
No, | ||
} | ||
|
||
impl FromStr for YesNo { | ||
type Err = color_eyre::eyre::Error; | ||
|
||
fn from_str(input: &str) -> Result<Self, Self::Err> { | ||
let lower = input.trim().to_lowercase(); | ||
match lower.as_str() { | ||
"yes" | "y" => Ok(Self::Yes), | ||
"no" | "n" => Ok(Self::No), | ||
e => Err(eyre!("Failed to parse {} into 'yes' or 'no'", e)), | ||
} | ||
} | ||
} | ||
|
||
impl YesNo { | ||
pub fn wait_for_decision() -> Result<Self> { | ||
let yes = loop { | ||
let mut input = String::new(); | ||
std::io::stdin() | ||
.read_line(&mut input) | ||
.wrap_err("Failed to read line from stdin")?; | ||
if let Ok(yn) = crate::cli_input::YesNo::from_str(&input) { | ||
log::trace!("Parsed {:?}", yn); | ||
break yn; | ||
} | ||
}; | ||
Ok(yes) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
pub mod errors; | ||
|
||
mod balance; | ||
mod cli_input; | ||
pub mod commands; | ||
pub mod delta; | ||
pub mod month; | ||
|