2020-02-28 12:02:29 +00:00
import click
2021-04-01 09:24:00 +00:00
import sys
2020-02-28 12:02:29 +00:00
2021-08-23 10:33:04 +00:00
from staking_deposit . cli . existing_mnemonic import existing_mnemonic
2023-01-06 10:17:28 +00:00
from staking_deposit . cli . generate_bls_to_execution_change import generate_bls_to_execution_change
2021-08-23 10:33:04 +00:00
from staking_deposit . cli . new_mnemonic import new_mnemonic
from staking_deposit . utils . click import (
2021-04-08 11:56:10 +00:00
captive_prompt_callback ,
choice_prompt_func ,
2021-04-19 13:07:13 +00:00
jit_option ,
2021-04-08 11:56:10 +00:00
)
2021-08-23 10:33:04 +00:00
from staking_deposit . utils import config
from staking_deposit . utils . constants import INTL_LANG_OPTIONS
from staking_deposit . 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 ,
)
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 ( )
2020-09-28 14:49:37 +00:00
@click.group ( )
2021-04-01 09:24:00 +00:00
@click.pass_context
2021-04-19 13:07:13 +00:00
@jit_option (
2021-04-01 09:24:00 +00:00
' --language ' ,
2021-04-08 11:56:10 +00:00
callback = captive_prompt_callback (
lambda language : fuzzy_reverse_dict_lookup ( language , INTL_LANG_OPTIONS ) ,
2021-05-04 13:46:32 +00:00
choice_prompt_func ( lambda : ' Please choose your language ' , get_first_options ( INTL_LANG_OPTIONS ) ) ,
2021-04-08 11:56:10 +00:00
) ,
2021-04-01 09:24:00 +00:00
default = ' English ' ,
2021-04-19 10:30:40 +00:00
help = ' The language you wish to use the CLI in. ' ,
2021-04-08 11:56:10 +00:00
prompt = choice_prompt_func ( lambda : ' Please choose your language ' , get_first_options ( INTL_LANG_OPTIONS ) ) ( ) ,
2021-04-01 09:24:00 +00:00
type = str ,
)
2021-04-27 13:18:28 +00:00
@click.option (
' --non_interactive ' ,
default = False ,
is_flag = True ,
2023-03-13 15:44:56 +00:00
help = ' Disables interactive prompts. Warning: with this flag, there will be no confirmation step(s) to verify the input value(s). Please use it carefully. ' , # noqa: E501
hidden = False ,
2021-04-27 13:18:28 +00:00
)
def cli ( ctx : click . Context , language : str , non_interactive : bool ) - > None :
2021-04-01 09:24:00 +00:00
config . language = language
2021-04-27 13:18:28 +00:00
config . non_interactive = non_interactive # Remove interactive commands
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 )
2023-01-06 10:17:28 +00:00
cli . add_command ( generate_bls_to_execution_change )
2020-09-28 14:49:37 +00:00
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 ( )
2023-02-10 15:27:41 +00:00
print ( ' \n ***Using the tool on an offline and secure device is highly recommended to keep your mnemonic safe.*** \n ' )
2020-09-28 14:49:37 +00:00
cli ( )