Skip to content

Commit

Permalink
Do not prompt for language when --non_interactive (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
yorickdowne authored Sep 1, 2024
1 parent a20685d commit 20c0272
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ethstaker_deposit/deposit.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
captive_prompt_callback,
choice_prompt_func,
jit_option,
deactivate_prompts_callback
)
from ethstaker_deposit.utils import config
from ethstaker_deposit.utils.constants import INTL_LANG_OPTIONS
Expand Down Expand Up @@ -80,6 +81,7 @@ def list_commands(self, ctx: click.Context) -> list[str]:
)
@click.option(
'--non_interactive',
callback=deactivate_prompts_callback(["language"]),
default=False,
is_flag=True,
help=(
Expand Down
21 changes: 21 additions & 0 deletions ethstaker_deposit/utils/click.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

from ethstaker_deposit.exceptions import ValidationError
from ethstaker_deposit.utils import config
# To work around an issue with disabling language prompt and CLIRunner() isolation
from ethstaker_deposit.utils.constants import INTL_LANG_OPTIONS
from ethstaker_deposit.utils.intl import (
get_first_options,
)


def _value_of(f: Union[Callable[[], Any], Any]) -> Any:
Expand Down Expand Up @@ -140,3 +145,19 @@ def choice_prompt_func(prompt_func: Callable[[], str], choices: Sequence[str]) -
output = output + ', '
output = output + ']'
return lambda: '%s %s: ' % (prompt_func(), output)


def deactivate_prompts_callback(param_names: list[str]) -> Callable[[click.Context, str, str], Any]:
def callback(ctx: click.Context, param: Any, value: str) -> Any:
if value:
for p in ctx.command.params:
if isinstance(p, click.Option) and p.name in param_names and p.prompt is not None:
p.prompt = None
else: # CLIRunner() is not as isolated as it should be. Restore the language prompt during tests
for p in ctx.command.params:
if isinstance(p, click.Option) and p.prompt is None:
if p.name == 'language':
p.prompt = choice_prompt_func(lambda: 'Please choose your language',
get_first_options(INTL_LANG_OPTIONS))()
return value
return callback

0 comments on commit 20c0272

Please sign in to comment.