in src/main.rs [1858:1921]
fn do_cmd_renew(out: &Arc<dyn Out>, cfg: &Config, store: &mut Store, sub_args: &RenewArgs) {
assert!(sub_args.expiring ^ sub_args.crate_name.is_some());
// We need the cache to map user ids to user names, though we can work around it if there is an
// error.
let cache = Cache::acquire(cfg).ok();
let new_end_date = cfg.today() + chrono::Months::new(12);
let mut renewing: WildcardAuditRenewal;
if let Some(name) = &sub_args.crate_name {
match WildcardAuditRenewal::single_crate(name, store) {
Some(renewal) => {
renewing = renewal;
if renewing.is_empty() {
info!("no wildcard audits for {name} are eligible for renewal (all have `renew = false`)");
return;
}
}
None => {
warn!("ran `renew {name}`, but there are no wildcard audits for the crate");
return;
}
}
} else {
// Find and update all expiring crates.
assert!(sub_args.expiring);
renewing = WildcardAuditRenewal::expiring(cfg, store, !sub_args.include_inactive);
if renewing.is_empty() {
info!("no wildcard audits that are eligible for renewal have expired or are expiring in the next {WILDCARD_AUDIT_EXPIRATION_STRING}");
return;
}
}
renewing.renew(new_end_date);
writeln!(
out,
"Updated wildcard audits for the following crates and publishers to expire on {new_end_date}:"
);
let user_string = |user_id: u64| -> String {
cache
.as_ref()
.and_then(|c| c.get_crates_user_info(user_id))
.map(|n| n.to_string())
.unwrap_or_else(|| format!("id={}", user_id))
};
for (name, entries) in renewing.crates {
writeln!(
out,
" {}: {:80}",
name,
string_format::FormatShortList::new(
entries
.iter()
.map(|(entry, _)| user_string(entry.user_id))
.collect()
)
);
}
}