fix(idf_tools): Validate input features

This commit is contained in:
Radim Karniš
2025-03-18 16:09:37 +01:00
parent 5cbd2a3877
commit 1aeb50d497
2 changed files with 22 additions and 9 deletions

View File

@@ -1783,14 +1783,24 @@ def process_and_check_features(idf_env_obj: IDFEnv, features_str: str) -> List[s
"""
new_features = []
remove_features = []
for new_feature_candidate in features_str.split(','):
invalid_features = []
for new_feature_candidate in [feature for feature in features_str.split(',') if feature != '']:
# Feature to be added/removed needs to be checked if valid
sanitized_feat = new_feature_candidate.lstrip('-+')
if not os.path.isfile(feature_to_requirements_path(sanitized_feat)):
invalid_features += [sanitized_feat]
continue
if new_feature_candidate.startswith('-'):
remove_features += [new_feature_candidate.lstrip('-')]
else:
new_feature_candidate = new_feature_candidate.lstrip('+')
# Feature to be added needs to be checked if is valid
if os.path.isfile(feature_to_requirements_path(new_feature_candidate)):
new_features += [new_feature_candidate]
new_features += [new_feature_candidate.lstrip('+')]
if invalid_features:
fatal(f'The following selected features are not valid: {", ".join(invalid_features)}')
raise SystemExit(1)
idf_env_obj.get_active_idf_record().update_features(tuple(new_features), tuple(remove_features))
return idf_env_obj.get_active_idf_record().features