From bd2a198c9442335ae2edabaad81a2e06327d87b5 Mon Sep 17 00:00:00 2001 From: Peter Eisenmann Date: Fri, 25 Aug 2023 22:43:41 +0200 Subject: [PATCH] config: make option names optional --- example_config/config.yaml | 6 +++--- example_config/config_to_pot.py | 2 +- src/provider/choices_provider.py | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/example_config/config.yaml b/example_config/config.yaml index a96c3f2..c344bd9 100644 --- a/example_config/config.yaml +++ b/example_config/config.yaml @@ -77,7 +77,8 @@ skip_locale: no # keyword string Forwarded to the installation script as is. # suggested bool Optional. Whether installation defaults to yes. # options list A list of options, with each option having: -# name string Option name presented to user. Translatable. +# name string Optional. Name presented to user. Translatable. +# Value of 'option' is used when not given. # option string Like 'keyword' for non-options, forwarded as-is when chosen. # # Default: [], suggested: False, description: '', icon_path: fallback icon @@ -96,12 +97,11 @@ additional_software: description : 'Select your favorite option' icon_path : '/etc/os-installer/icons/options-symbolic.svg' options : + - option : 'Nothing' - name : 'Option 1' option : 'package_1' - name : 'Option 2' option : 'package_2' - - name : 'Option 3' - option : 'package_3' # List of features that can additionally be selected. Very similar # to `additional_software`, but meant for more generic features. Can diff --git a/example_config/config_to_pot.py b/example_config/config_to_pot.py index 2fe537b..691a0f1 100644 --- a/example_config/config_to_pot.py +++ b/example_config/config_to_pot.py @@ -33,7 +33,7 @@ def handle_choices(choices, pot_file): for option in options: if 'name' in option: add_to_pot(option['name'], pot_file) - else: + elif not 'option' in option: print(f'Invalid option: {option}') diff --git a/src/provider/choices_provider.py b/src/provider/choices_provider.py index 354a291..c16b65e 100644 --- a/src/provider/choices_provider.py +++ b/src/provider/choices_provider.py @@ -40,10 +40,11 @@ def handle_choice(choice): options = [] for option in choice['options']: - if (not 'option' in option or not 'name' in option): + if not 'option' in option: print(f'Option for {name} not correctly configured: {option}') continue - options.append(Option(option['name'], option['option'])) + name = option['name'] if 'name' in option else option['option'] + options.append(Option(name, option['option'])) if len(options) == 0: print(f'No valid options found for {name}')