Skip to content

Commit

Permalink
feat(cli): add version + minor change (#20)
Browse files Browse the repository at this point in the history
✨ add `version` subcommand
🔨 make options required
🔖 add the `__version__` variable to keep track of version

link #20 #26
  • Loading branch information
rafidini committed Jan 21, 2023
1 parent 2626ed4 commit c3ff6e1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
3 changes: 3 additions & 0 deletions ergpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
'helper_functions',
'logs'
]

# Version of the package
__version__: str = '0.1.10.0'
30 changes: 21 additions & 9 deletions ergpy/cli.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Packages
import typing
import click
import ergpy
import ergpy.helper_functions as ergpy_help


# Constants
OPTION__REQUIRED: dict = {'required': True}
OPTION_NODE_URL: dict = {
'envvar':'NODE_URL',
'type':click.STRING,
Expand Down Expand Up @@ -32,7 +34,11 @@
'type': click.STRING,
'help': 'Address of the sender'
}

OPTION_TOKENS: dict = {
'type': click.STRING,
'help': 'Tokens',
'multiple': True
}

# Utils
def secho_iterable(iterable: typing.Iterable, color: str='blue'):
Expand Down Expand Up @@ -63,6 +69,11 @@ def cli():
pass

# Get subcommands
@cli.command()
def version():
"""Show the current version of the package"""
click.secho(f'ergpy {ergpy.__version__}', fg='blue')

@cli.group()
def get():
"""Retrieve information about wallet address, box info..."""
Expand All @@ -83,10 +94,10 @@ def create():

# Commands
@click.command()
@click.option('--amount', **OPTION_AMOUNT)
@click.option('--wallet-mnemonic', **OPTION_WALLET_MNEMONIC)
@click.option('--mnemonic-password', **OPTION_MNEMONIC_PASSWORD)
@click.option('--node-url', **OPTION_NODE_URL)
@click.option('--amount', **OPTION_AMOUNT, **OPTION__REQUIRED)
@click.option('--wallet-mnemonic', **OPTION_WALLET_MNEMONIC, **OPTION__REQUIRED)
@click.option('--mnemonic-password', **OPTION_MNEMONIC_PASSWORD, **OPTION__REQUIRED)
@click.option('--node-url', **OPTION_NODE_URL, **OPTION__REQUIRED)
def wallet_address(node_url: str, amount: int, wallet_mnemonic: str, mnemonic_password: str = None):
"""Retrieve informations about (a) wallet address(es)."""
click.secho(f'You selected : Get (a) wallet address(es)', fg='blue')
Expand All @@ -107,10 +118,11 @@ def wallet_address(node_url: str, amount: int, wallet_mnemonic: str, mnemonic_pa
click.secho(f'Failed to retrieve wallet address(es) : {e}', fg='red')

@click.command()
@click.option('--node-url', **OPTION_NODE_URL)
@click.option('--index', **OPTION_INDEX)
@click.option('--sender-address', **OPTION_SENDER_ADDRESS)
def box_info(node_url: str, index: int, sender_address: str, tokens: list = None):
@click.option('--node-url', **OPTION_NODE_URL, **OPTION__REQUIRED)
@click.option('--index', **OPTION_INDEX, **OPTION__REQUIRED)
@click.option('--sender-address', **OPTION_SENDER_ADDRESS, **OPTION__REQUIRED)
@click.option('--tokens', **OPTION_TOKENS)
def box_info(node_url: str, index: int, sender_address: str, tokens: list=None):
"""Retrieve informations about box."""
click.secho(f'You selected : Get box informations', fg='blue')
click.echo(f'Connecting to blockchain @ {node_url}')
Expand Down

0 comments on commit c3ff6e1

Please sign in to comment.