add upper bound to the padding option
This commit is contained in:
parent
4bd7e0283f
commit
583bc8866a
|
|
@ -40,6 +40,7 @@ pub struct Args {
|
|||
pub enum CliError {
|
||||
CouldNotParseTime,
|
||||
CouldNotParseDate,
|
||||
PaddingTooLarge,
|
||||
CouldNotParseTimezone(String),
|
||||
CouldNotGenerateTimetable(String),
|
||||
}
|
||||
|
|
@ -49,6 +50,7 @@ impl fmt::Display for CliError {
|
|||
let message = match *self {
|
||||
Self::CouldNotParseTime => "Couldn't parse time".to_string(),
|
||||
Self::CouldNotParseDate => "Couldn't parse date".to_string(),
|
||||
Self::PaddingTooLarge => "Padding option cannot be larger than 12".to_string(),
|
||||
Self::CouldNotParseTimezone(ref tz) => {
|
||||
format!("Couldn't parse timezone {}", tz).to_string()
|
||||
}
|
||||
|
|
@ -70,6 +72,10 @@ pub fn print_timezones(
|
|||
local_timezone: &String,
|
||||
padding_hours: i8,
|
||||
) -> Result<(), CliError> {
|
||||
if padding_hours > 12 {
|
||||
return Err(CliError::PaddingTooLarge);
|
||||
};
|
||||
|
||||
let parsed_time = if let Some(t) = time {
|
||||
if let Ok(hour) = t.parse::<u32>() {
|
||||
NaiveTime::from_hms_opt(hour, 0, 0).ok_or(CliError::CouldNotParseTime)?
|
||||
|
|
|
|||
Loading…
Reference in New Issue