Skip to content

Commit

Permalink
✨ Add 'ask' option for refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
mleduque committed Dec 9, 2023
1 parent d72f683 commit 766d6f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ fn use_from_cache(opts: &DownloadOpts, file_name: &PathBuf) -> Result<bool> {
match opts.refresh {
RefreshCondition::Always => Ok(false),
RefreshCondition::Never => Ok(file_name.exists()),
RefreshCondition::Ask => {
let name = file_name.as_os_str().to_string_lossy();
Ok(dialoguer::Confirm::new().with_prompt(format!("Refresh this mod archive? ({name})")).interact()?)
}
RefreshCondition::Duration(duration) => {
let metadata = match std::fs::metadata(file_name) {
Err(error) if error.kind() == ErrorKind::NotFound => return Ok(false),
Expand Down
3 changes: 3 additions & 0 deletions src/module/refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub enum RefreshCondition {
/// - 1day
/// - 30min
Duration(Duration),
Ask,
}

serde_with::serde_conv!(
Expand All @@ -31,6 +32,7 @@ serde_with::serde_conv!(
|condition: &RefreshCondition| match condition {
RefreshCondition::Never => "never".to_string(),
RefreshCondition::Always => "always".to_string(),
RefreshCondition::Ask => "ask".to_string(),
RefreshCondition::Duration(duration) => humantime::format_duration(*duration).to_string(),
},
|value: String| RefreshCondition::from_str(&value)
Expand All @@ -43,6 +45,7 @@ impl FromStr for RefreshCondition {
return match s {
"never" => Ok(RefreshCondition::Never),
"always" => Ok(RefreshCondition::Always),
"ask" => Ok(RefreshCondition::Ask),
value => match parse_duration(value) {
Ok(result) => Ok(RefreshCondition::Duration(result)),
Err(error) => Err(ParseRefreshConditionError(error.to_string()))
Expand Down

0 comments on commit 766d6f4

Please sign in to comment.