pub struct LintPolicy { /* private fields */ }Expand description
How serious each kind of finding is for one program.
By default a misspelled flag, a misspelled variable and a flag given to a subcommand it does not belong to are all errors: the user’s intent is clear and wrong, and carrying on would run the program without the setting they asked for. A project that has a reason to be more forgiving says so, once, in its own code:
use argenv_resolve::{LintPolicy, Severity};
// Everything strict (this is the default):
let strict = LintPolicy::default();
// The previous behaviour: surface typos, never stop for them.
let lenient = LintPolicy::lenient();
// Or one class at a time, for example a wrapper that forwards unknown flags to a child:
let wrapper = LintPolicy::default().unknown_flags(Severity::Warning);The findings themselves do not change with the policy, only how seriously they are taken. A problem with a value (out of domain, unparseable, missing) is always an error: there is no usable reading of it.
Implementations§
Source§impl LintPolicy
impl LintPolicy
Sourcepub const fn strict() -> Self
pub const fn strict() -> Self
Typos in flags and variables are errors; use of a deprecated input is a warning.
Sourcepub const fn lenient() -> Self
pub const fn lenient() -> Self
Typos are surfaced but never stop the program. This was the behaviour before strictness became the default; it is the right choice for a program that forwards flags it does not declare, or that runs in environments it does not control.
Sourcepub const fn unknown_flags(self, severity: Severity) -> Self
pub const fn unknown_flags(self, severity: Severity) -> Self
How seriously to take a flag that no input declares.
Sourcepub const fn unknown_variables(self, severity: Severity) -> Self
pub const fn unknown_variables(self, severity: Severity) -> Self
How seriously to take a variable that closely resembles a declared one.
Sourcepub const fn out_of_scope_flags(self, severity: Severity) -> Self
pub const fn out_of_scope_flags(self, severity: Severity) -> Self
How seriously to take a flag that is declared, but for other subcommands than the one
running (for example --dry-run, which belongs to create, given to delete).
Sourcepub const fn deprecated(self, severity: Severity) -> Self
pub const fn deprecated(self, severity: Severity) -> Self
How seriously to take the use of a deprecated input.