From f88638984ada9dd7d1fe8b55bd7674745132559a Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Tue, 3 Dec 2024 15:58:49 +0100 Subject: [PATCH] Verify every dependency is required (#65) If not, the generated code will not work Fixes #64 --- CHANGELOG.md | 1 + src/main.rs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a77a867..cb9adac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Update the resulting binary name (#62) ### Fixed +- Verify the required options are provided (#65) ### Removed diff --git a/src/main.rs b/src/main.rs index ad2c317..1ee0cf8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -83,6 +83,13 @@ impl GeneratorOptionItem { GeneratorOptionItem::Option(option) => option.chips, } } + + fn enables(&self) -> &[&str] { + match self { + GeneratorOptionItem::Category(_) => &[], + GeneratorOptionItem::Option(option) => option.enables, + } + } } static OPTIONS: &[GeneratorOptionItem] = &[ @@ -469,6 +476,18 @@ fn process_options(args: &Args) { ); process::exit(-1); } + if !option_item + .enables() + .iter() + .all(|requirement| args.option.contains(&requirement.to_string())) + { + log::error!( + "Option '{}' requires {}", + option_item.name(), + option_item.enables().join(", ") + ); + process::exit(-1); + } } } }