Skip to content

Commit

Permalink
Do not prompt for language when --non_interactive
Browse files Browse the repository at this point in the history
  • Loading branch information
yorickdowne committed Aug 31, 2024
1 parent c17acef commit de62299
Show file tree
Hide file tree
Showing 2 changed files with 24 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 @@ -15,6 +15,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 @@ -81,6 +82,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
22 changes: 22 additions & 0 deletions ethstaker_deposit/utils/click.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@
Sequence,
Tuple,
Union,
List,
)

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 +146,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 de62299

Please sign in to comment.