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

Only delete old projects (skip active projects) #66

Merged
merged 5 commits into from
Nov 26, 2022

Conversation

gabrielztk
Copy link
Contributor

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!

Copy link
Owner

@tbillington tbillington left a 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)
}

kondo-lib/src/lib.rs Outdated Show resolved Hide resolved
kondo-lib/src/lib.rs Outdated Show resolved Hide resolved
kondo-lib/src/lib.rs Outdated Show resolved Hide resolved
kondo-lib/src/lib.rs Outdated Show resolved Hide resolved
kondo-lib/src/lib.rs Outdated Show resolved Hide resolved
@gabrielztk
Copy link
Contributor Author

Thanks for the tips!
I will implement them and look over the code you wrote.

@tbillington tbillington merged commit f3924f8 into tbillington:master Nov 26, 2022
@tbillington
Copy link
Owner

Thank you for contribution @gabrielztk :)

@gabrielztk
Copy link
Contributor Author

Thanks for being so welcoming and for taking the time to help me @tbillington!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Only delete old project (skip active project)
2 participants