-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
Only delete old projects (skip active projects) #66
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, appreciate you taking a crack at this! It nails the functionality, just a few things we can do to improve the robustness.
My recommendation would also be to move this from the lib to the cli (kondo/src/main.rs
) as it's functionality specific to the cli implementation.
Here is how I would write it to address the issues raised, let me know if you have any questions :)
#[derive(Debug)]
pub enum ParseAgeFilterError {
ParseIntError(ParseIntError),
InvalidUnit,
}
impl fmt::Display for ParseAgeFilterError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ParseAgeFilterError::ParseIntError(e) => e.fmt(f),
ParseAgeFilterError::InvalidUnit => {
"invalid age unit, must be one of m, h, d, w, M, y".fmt(f)
}
}
}
}
impl From<ParseIntError> for ParseAgeFilterError {
fn from(e: ParseIntError) -> Self {
Self::ParseIntError(e)
}
}
pub fn parse_age_filter(age_filter: &str) -> Result<u64, ParseAgeFilterError> {
let (digit_end, unit) = age_filter
.char_indices()
.last()
.ok_or(ParseAgeFilterError::InvalidUnit)?;
let multiplier = match unit {
'm' => MINUTE,
'h' => HOUR,
'd' => DAY,
'w' => WEEK,
'M' => MONTH,
'y' => YEAR,
_ => return Err(ParseAgeFilterError::InvalidUnit),
};
let count = age_filter[..digit_end].parse::<u64>()?;
let seconds = count * multiplier;
Ok(seconds)
}
Thanks for the tips! |
…e the sugested changes in code
Thank you for contribution @gabrielztk :) |
Thanks for being so welcoming and for taking the time to help me @tbillington! |
Closes #64
Option older was implemented so that only projects that are older than the set value are looked over for cleaning.
PS: I'm still new to Open Source, if I did anything wrong please let me know!