in src/main.rs [1676:1731]
fn cmd_add_exemption(
_out: &Arc<dyn Out>,
cfg: &Config,
sub_args: &AddExemptionArgs,
) -> Result<(), miette::Report> {
// Add an exemption entry
let mut store = Store::acquire_offline(cfg)?;
let notes = sub_args.notes.clone();
let criteria = if sub_args.criteria.is_empty() {
// TODO: provide an interactive prompt for this
vec![store.config.default_criteria.clone().into()]
} else {
sub_args
.criteria
.iter()
.map(|s| s.to_owned().into())
.collect()
};
let suggest = !sub_args.no_suggest;
// FIXME: can/should we check if the version makes sense..?
if !sub_args.force
&& !foreign_packages(&cfg.metadata, &store.config).any(|pkg| pkg.name == sub_args.package)
{
// ERRORS: immediate fatal diagnostic? should we allow you to certify random packages?
// You're definitely *allowed* to have unused audits, otherwise you'd be constantly deleting
// useful audits whenever you update your dependencies! But this might be a useful guard
// against typosquatting or other weird issues?
return Err(miette!(
"'{}' isn't one of your foreign packages",
sub_args.package
));
}
// Ok! Ready to commit the audit!
let new_entry = ExemptedDependency {
criteria,
notes,
version: sub_args.version.clone(),
suggest,
};
store
.config
.exemptions
.entry(sub_args.package.clone())
.or_default()
.push(new_entry);
store.commit()?;
Ok(())
}