Skip to content

Commit

Permalink
refactor(frontend/cli_options): factor the prefixes with constants
Browse files Browse the repository at this point in the history
  • Loading branch information
W95Psp committed Nov 13, 2024
1 parent 174775e commit f5f39f0
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions hax-types/src/cli_options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,20 @@ pub struct InclusionClause {
pub namespace: Namespace,
}

const PREFIX_INCLUDED_TRANSITIVE: &str = "+";
const PREFIX_INCLUDED_SHALLOW: &str = "+~";
const PREFIX_INCLUDED_NONE: &str = "+!";
const PREFIX_SIGNATURE_ONLY: &str = "+:";
const PREFIX_EXCLUDED: &str = "-";

impl ToString for InclusionClause {
fn to_string(&self) -> String {
let kind = match self.kind {
InclusionKind::Included(DepsKind::Transitive) => "+",
InclusionKind::Included(DepsKind::Shallow) => "+~",
InclusionKind::Included(DepsKind::None) => "+!",
InclusionKind::SignatureOnly => "+:",
InclusionKind::Excluded => "-",
InclusionKind::Included(DepsKind::Transitive) => PREFIX_INCLUDED_TRANSITIVE,
InclusionKind::Included(DepsKind::Shallow) => PREFIX_INCLUDED_SHALLOW,
InclusionKind::Included(DepsKind::None) => PREFIX_INCLUDED_NONE,
InclusionKind::SignatureOnly => PREFIX_SIGNATURE_ONLY,
InclusionKind::Excluded => PREFIX_EXCLUDED,
};
format!("{kind}{}", self.namespace.to_string())
}
Expand All @@ -248,11 +254,11 @@ pub fn parse_inclusion_clause(
)
};
let kind = match &prefix[..] {
"+" => InclusionKind::Included(DepsKind::Transitive),
"+~" => InclusionKind::Included(DepsKind::Shallow),
"+!" => InclusionKind::Included(DepsKind::None),
"+:" => InclusionKind::SignatureOnly,
"-" => InclusionKind::Excluded,
PREFIX_INCLUDED_TRANSITIVE => InclusionKind::Included(DepsKind::Transitive),
PREFIX_INCLUDED_SHALLOW => InclusionKind::Included(DepsKind::Shallow),
PREFIX_INCLUDED_NONE => InclusionKind::Included(DepsKind::None),
PREFIX_SIGNATURE_ONLY => InclusionKind::SignatureOnly,
PREFIX_EXCLUDED => InclusionKind::Excluded,
prefix => Err(format!(
"Expected `+`, `+~`, `+!`, `+:` or `-`, got an `{prefix}`"
))?,
Expand Down

0 comments on commit f5f39f0

Please sign in to comment.