Skip to content

Commit

Permalink
Allow negative requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Feb 10, 2025
1 parent fb7f337 commit d44ec4b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- When using `embassy` option, `async_main.rs` file was renamed to `main.rs` (#93)
- The UI no longer allows selecting options with missing requirements, and does not allow deselecting
options that are required by other options. (#101)
- Options can now declare negative requirements (e.g. `!alloc` can not be enabled if `alloc` is used) (#101)

### Fixed

Expand Down
28 changes: 26 additions & 2 deletions src/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,35 @@ impl Repository {
return false;
}

for requirement in option.requires {
if !self.is_selected(requirement) {
// Are this option's requirements met?
for &requirement in option.requires {
let (key, expected) = if let Some(requirement) = requirement.strip_prefix('!') {
(requirement, false)
} else {
(requirement, true)
};

if self.is_selected(key) != expected {
return false;
}
}

// Does any of the enabled options have a requirement against this one?
for selected in self.selected.iter() {
let Some(selected_option) = find_option(selected, self.options) else {
ratatui::restore();
panic!("selected option not found: {selected}");
};

for requirement in selected_option.requires.iter() {
if let Some(requirement) = requirement.strip_prefix('!') {
if requirement == option.name {
return false;
}
}
}
}

true
}

Expand Down

0 comments on commit d44ec4b

Please sign in to comment.