Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes parameters of str type case-insensitive #1054

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions cid/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,18 @@ def get_parameters():
return dict(params)


def get_yesno_parameter(param_name, message, default=None, break_on_ctrl_c=True):
def get_yesno_parameter(param_name: str, message: str, default: str | None = None, break_on_ctrl_c = True):
logger.debug(f'getting param {param_name}')
param_name = param_name.replace('_', '-')
mapping = {True: True, False:False, 'yes': True, 'no': False}
if param_name in params and params.get(param_name) != None:
return mapping[params.get(param_name)]
if param_name in params and params.get(param_name) == None:
unset_parameter(param_name)
if default != None:
mapping = {True: True, False: False, 'yes': True, 'no': False}
if param_name in params:
param_value = params.get(param_name)
if param_value is not None:
return mapping[param_value]
else:
unset_parameter(param_name)
if default is not None:
default = default.lower()
default = 'yes' if mapping[default] else 'no'
res = get_parameter(param_name, message=message, choices=['yes', 'no'], default=default, break_on_ctrl_c=break_on_ctrl_c)
params[param_name] = (res == 'yes')
Expand Down
Loading