2020-02-28 12:02:29 +00:00
|
|
|
import click
|
2021-04-01 09:24:00 +00:00
|
|
|
from typing import (
|
|
|
|
Any,
|
|
|
|
)
|
|
|
|
import sys
|
2020-02-28 12:02:29 +00:00
|
|
|
|
2020-09-28 14:49:37 +00:00
|
|
|
from eth2deposit.cli.existing_mnemonic import existing_mnemonic
|
|
|
|
from eth2deposit.cli.new_mnemonic import new_mnemonic
|
2021-04-01 09:24:00 +00:00
|
|
|
from eth2deposit.utils import config
|
2021-04-08 10:08:59 +00:00
|
|
|
from eth2deposit.utils.constants import INTL_LANG_OPTIONS
|
2021-04-01 09:24:00 +00:00
|
|
|
from eth2deposit.utils.intl import (
|
2021-04-08 10:08:59 +00:00
|
|
|
get_first_options,
|
|
|
|
fuzzy_reverse_dict_lookup,
|
2021-04-01 09:24:00 +00:00
|
|
|
load_text,
|
|
|
|
)
|
2021-04-08 10:08:59 +00:00
|
|
|
from eth2deposit.exceptions import ValidationError
|
2020-02-28 12:02:29 +00:00
|
|
|
|
|
|
|
|
2020-05-19 13:34:16 +00:00
|
|
|
def check_python_version() -> None:
|
2020-03-10 18:40:19 +00:00
|
|
|
'''
|
|
|
|
Checks that the python version running is sufficient and exits if not.
|
|
|
|
'''
|
|
|
|
if sys.version_info < (3, 7):
|
2021-04-01 09:24:00 +00:00
|
|
|
click.pause(load_text(['err_python_version']))
|
2020-03-10 18:40:19 +00:00
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
|
2021-04-01 09:24:00 +00:00
|
|
|
def process_language_callback(ctx: click.Context, param: Any, language: str) -> str:
|
|
|
|
'''
|
|
|
|
Validates the selected language and returns its ISO 639-1 name.
|
|
|
|
'''
|
|
|
|
while True:
|
|
|
|
try:
|
2021-04-08 10:08:59 +00:00
|
|
|
return fuzzy_reverse_dict_lookup(language, INTL_LANG_OPTIONS)
|
|
|
|
except ValidationError:
|
|
|
|
language = click.prompt('Please select a valid language (%s): ' % get_first_options(INTL_LANG_OPTIONS))
|
2021-04-01 09:24:00 +00:00
|
|
|
|
|
|
|
|
2020-09-28 14:49:37 +00:00
|
|
|
@click.group()
|
2021-04-01 09:24:00 +00:00
|
|
|
@click.pass_context
|
|
|
|
@click.option(
|
|
|
|
'--language',
|
|
|
|
callback=process_language_callback,
|
|
|
|
default='English',
|
2021-04-08 10:08:59 +00:00
|
|
|
prompt='Please choose your language (%s)' % get_first_options(INTL_LANG_OPTIONS),
|
2021-04-01 09:24:00 +00:00
|
|
|
required=True,
|
|
|
|
type=str,
|
|
|
|
)
|
|
|
|
def cli(ctx: click.Context, language: str) -> None:
|
|
|
|
config.language = language
|
2020-02-28 12:02:29 +00:00
|
|
|
|
|
|
|
|
2020-09-28 14:49:37 +00:00
|
|
|
cli.add_command(existing_mnemonic)
|
|
|
|
cli.add_command(new_mnemonic)
|
|
|
|
|
2020-09-28 15:20:08 +00:00
|
|
|
|
2020-02-28 12:02:29 +00:00
|
|
|
if __name__ == '__main__':
|
2020-09-28 14:49:37 +00:00
|
|
|
check_python_version()
|
|
|
|
cli()
|