diff --git a/installation_instruction/__main__.py b/installation_instruction/__main__.py index 73ffd7c..83a728c 100644 --- a/installation_instruction/__main__.py +++ b/installation_instruction/__main__.py @@ -29,6 +29,22 @@ License: {__license__} Repository: {__repository__}""" +def _get_system(option_types): + + system = platform.system() + system_names = { + 'Linux': 'lin', + 'Darwin': 'mac', + 'Windows': 'win', + } + + sub_default = system_names.get(system,None) + for type in option_types: + default_type = type.lower() + if sub_default in default_type: + return type + + return None class ConfigReadCommand(click.MultiCommand): """ @@ -43,22 +59,6 @@ def __init__(self, *args, **kwargs): options_metavar="", ) - def _get_system(self, option_types): - system = platform.system().lower() - system_names = { - 'linux': 'lin', - 'linux2': 'lin', - 'darwin': 'mac', - 'win32': 'win', - } - if system in system_names.keys: - system = system_names.get(system) - for type in option_types: - if system in type.lower(): - return type - - return None - def get_command(self, ctx, config_file: str) -> click.Command|None: if not isfile(config_file): @@ -74,7 +74,7 @@ def get_command(self, ctx, config_file: str) -> click.Command|None: for option in options: if '__os__' in option.name: - system_default = self._get_system(option.type.choices) + system_default = _get_system(option.type.choices) if system_default: option.default = system_default diff --git a/tests/data/test_install/install.cfg b/tests/data/test_install/install.cfg index bfdfe53..46513b2 100644 --- a/tests/data/test_install/install.cfg +++ b/tests/data/test_install/install.cfg @@ -8,6 +8,13 @@ properties: error_template: type: boolean default: false + __os__: + description: The operating system in which the package is installed. + enum: + - Windows + - macOS + - Linux + default: macOS required: - error_install - error_template