mirror of
https://gitlab.com/pulsechaincom/staking-deposit-cli.git
synced 2025-01-10 13:01:22 +00:00
Adds option auto function & file detection
This commit is contained in:
parent
d828bb5de0
commit
6e3a0a34de
@ -67,30 +67,30 @@ def generate_keys_arguments_decorator(function: Callable[..., Any]) -> Callable[
|
||||
'''
|
||||
decorators = [
|
||||
click.option(
|
||||
load_text('en', ['arguments_decorator', 'num_validators', 'argument']),
|
||||
help=load_text('en', ['arguments_decorator', 'num_validators', 'help']),
|
||||
prompt=load_text('en', ['arguments_decorator', 'num_validators', 'prompt']),
|
||||
load_text('en', ['num_validators', 'argument']),
|
||||
help=load_text('en', ['num_validators', 'help']),
|
||||
prompt=load_text('en', ['num_validators', 'prompt']),
|
||||
required=True,
|
||||
type=click.IntRange(0, 2**32 - 1),
|
||||
),
|
||||
click.option(
|
||||
load_text('en', ['arguments_decorator', 'folder', 'argument']),
|
||||
load_text('en', ['folder', 'argument']),
|
||||
default=os.getcwd(),
|
||||
help=load_text('en', ['arguments_decorator', 'folder', 'help']),
|
||||
help=load_text('en', ['folder', 'help']),
|
||||
type=click.Path(exists=True, file_okay=False, dir_okay=True),
|
||||
),
|
||||
click.option(
|
||||
load_text('en', ['arguments_decorator', 'chain', 'argument']),
|
||||
load_text('en', ['chain', 'argument']),
|
||||
default=MAINNET,
|
||||
help=load_text('en', ['arguments_decorator', 'chain', 'help']),
|
||||
prompt=load_text('en', ['arguments_decorator', 'chain', 'prompt']),
|
||||
help=load_text('en', ['chain', 'help']),
|
||||
prompt=load_text('en', ['chain', 'prompt']),
|
||||
type=click.Choice(ALL_CHAINS.keys(), case_sensitive=False),
|
||||
),
|
||||
click.password_option(
|
||||
load_text('en', ['arguments_decorator', 'keystore_password', 'argument']),
|
||||
load_text('en', ['keystore_password', 'argument']),
|
||||
callback=validate_password,
|
||||
help=load_text('en', ['arguments_decorator', 'keystore_password', 'help']),
|
||||
prompt=load_text('en', ['arguments_decorator', 'keystore_password', 'prompt']),
|
||||
help=load_text('en', ['keystore_password', 'help']),
|
||||
prompt=load_text('en', ['keystore_password', 'prompt']),
|
||||
),
|
||||
]
|
||||
for decorator in reversed(decorators):
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"arguments_decorator": {
|
||||
"generate_keys_arguments_decorator": {
|
||||
"num_validators": {
|
||||
"argument": "--num_validators",
|
||||
"help": "The number of validators keys you want to generate (you can always generate more later)",
|
||||
|
@ -18,13 +18,18 @@ def _get_from_dict(dataDict: Dict[str, Any], mapList: List[str]) -> str:
|
||||
return reduce(dict.get, mapList, dataDict) # type: ignore
|
||||
|
||||
|
||||
def load_text(lang: str, params: List[str]) -> str:
|
||||
def load_text(lang: str, params: List[str], file_path: str='', func: str='') -> str:
|
||||
'''
|
||||
Determine and return the appropriate internationalisation text for a given `lang` and `params`
|
||||
'''
|
||||
# Determine appropriate file
|
||||
file_path = inspect.stack()[1].filename
|
||||
file_path = file_path[:-3] + '.json' # replace .py with .json
|
||||
if file_path == '':
|
||||
# Auto-detect file-path based on call stack
|
||||
file_path = inspect.stack()[1].filename
|
||||
file_path = file_path[:-3] + '.json' # replace .py with .json
|
||||
|
||||
if func == '':
|
||||
# Auto-detect function based on call stack
|
||||
func = inspect.stack()[1].function
|
||||
|
||||
# Determine path to json text
|
||||
file_path_list = os.path.normpath(file_path).split(os.path.sep)
|
||||
@ -34,4 +39,4 @@ def load_text(lang: str, params: List[str]) -> str:
|
||||
# browse json until text is found
|
||||
with open(json_path) as f:
|
||||
text_dict = json.load(f)
|
||||
return _get_from_dict(text_dict, params)
|
||||
return _get_from_dict(text_dict, [func] + params)
|
||||
|
Loading…
Reference in New Issue
Block a user