diff --git a/silkaj/blockchain/blocks.py b/silkaj/blockchain/blocks.py index 04daed80406a7810de28495c1da50d01b76770f3..7d442a1534af8a57ec8690398c3460d545fa42c7 100644 --- a/silkaj/blockchain/blocks.py +++ b/silkaj/blockchain/blocks.py @@ -18,7 +18,7 @@ from collections import OrderedDict from operator import itemgetter from urllib.error import HTTPError -from click import IntRange, argument, command, option +import click from duniterpy.api import bma from pendulum import from_timestamp @@ -29,9 +29,9 @@ from silkaj.network import client_instance from silkaj.wot.tools import identity_of -@command("blocks", help="Display blocks: default: 0 for current window size") -@argument("number", default=0, type=IntRange(0, 5000)) -@option( +@click.command("blocks", help="Display blocks: default: 0 for current window size") +@click.argument("number", default=0, type=click.IntRange(0, 5000)) +@click.option( "--detailed", "-d", is_flag=True, diff --git a/silkaj/blockchain/verify.py b/silkaj/blockchain/verify.py index d78b20be4e00d95a600e3c846a591f6de8fc348b..218304d5f17acbca23638511328b2a20b8452070 100644 --- a/silkaj/blockchain/verify.py +++ b/silkaj/blockchain/verify.py @@ -17,7 +17,7 @@ import logging from typing import List from urllib.error import HTTPError -from click import INT, argument, command, progressbar +import click from duniterpy.api import bma from duniterpy.api.client import Client from duniterpy.documents import Block @@ -27,20 +27,20 @@ from silkaj.network import client_instance from silkaj.tools import message_exit -@command( +@click.command( "verify", help="Verify blocks` signatures. \ If only FROM_BLOCK is specified, it verifies from this block to the last block. \ If nothing specified, the whole blockchain gets verified.", ) -@argument("from_block", default=0, type=INT) -@argument("to_block", default=0, type=INT) +@click.argument("from_block", default=0, type=click.INT) +@click.argument("to_block", default=0, type=click.INT) def verify_blocks_signatures(from_block: int, to_block: int) -> None: client = client_instance() to_block = check_passed_blocks_range(client, from_block, to_block) invalid_blocks_signatures = [] # type: List[int] chunks_from = range(from_block, to_block + 1, BMA_MAX_BLOCKS_CHUNK_SIZE) - with progressbar(chunks_from, label="Processing blocks verification") as bar: + with click.progressbar(chunks_from, label="Processing blocks verification") as bar: for chunk_from in bar: chunk_size = get_chunk_size(from_block, to_block, chunks_from, chunk_from) logging.info( diff --git a/silkaj/cli.py b/silkaj/cli.py index 9e7ed070773a5fb4c9b70072fb661ff3c884b283..a147f2d5029133934349115b8f53ff77398683a7 100644 --- a/silkaj/cli.py +++ b/silkaj/cli.py @@ -15,7 +15,7 @@ import sys -from click import Context, group, help_option, option, pass_context, version_option +import click from duniterpy.api.endpoint import endpoint as du_endpoint from silkaj.about import about @@ -41,10 +41,10 @@ from silkaj.wot.membership import send_membership from silkaj.wot.status import status -@group() -@help_option("-h", "--help") -@version_option(SILKAJ_VERSION, "-v", "--version") -@option( +@click.group() +@click.help_option("-h", "--help") +@click.version_option(SILKAJ_VERSION, "-v", "--version") +@click.option( "--endpoint", "-ep", help=f"Default endpoint to reach Ğ1 currency by its official node\ @@ -52,43 +52,53 @@ from silkaj.wot.status import status This option allows to specify a custom endpoint as follow: <host>:<port>.\ In case no port is specified, it defaults to 443.", ) -@option( +@click.option( "--gtest", "-gt", is_flag=True, help=f"Default endpoint to reach ĞTest currency by its official node: \ {du_endpoint(G1_TEST_DEFAULT_ENDPOINT).host}", ) -@option( +@click.option( "--auth-scrypt", "--scrypt", is_flag=True, help="Scrypt authentication: default method", ) -@option("--nrp", help='Scrypt parameters: defaults N,r,p: "4096,16,1"') -@option( +@click.option("--nrp", help='Scrypt parameters: defaults N,r,p: "4096,16,1"') +@click.option( "--auth-file", "-af", help="Authentication file path", ) -@option("--auth-seed", "--seed", is_flag=True, help="Seed hexadecimal authentication") -@option("--auth-wif", "--wif", is_flag=True, help="WIF and EWIF authentication methods") -@option( +@click.option( + "--auth-seed", + "--seed", + is_flag=True, + help="Seed hexadecimal authentication", +) +@click.option( + "--auth-wif", + "--wif", + is_flag=True, + help="WIF and EWIF authentication methods", +) +@click.option( "--display", "-d", is_flag=True, help="Display the generated document before sending it", ) -@option( +@click.option( "--dry-run", "-n", is_flag=True, help="By-pass licence, confirmation. \ Do not send the document, but display it instead", ) -@pass_context +@click.pass_context def cli( - ctx: Context, + ctx: click.Context, endpoint: str, gtest: bool, auth_scrypt: bool, @@ -122,7 +132,7 @@ cli.add_command(license_command) @cli.group("blockchain", help="Blockchain related commands") -@help_option("-h", "--help") +@click.help_option("-h", "--help") def blockchain_group() -> None: pass @@ -134,7 +144,7 @@ blockchain_group.add_command(verify_blocks_signatures) @cli.group("money", help="Money management related commands") -@help_option("-h", "--help") +@click.help_option("-h", "--help") def money_group() -> None: pass @@ -145,7 +155,7 @@ money_group.add_command(transfer_money) @cli.group("wot", help="Web-of-Trust related commands") -@help_option("-h", "--help") +@click.help_option("-h", "--help") def wot_group() -> None: pass @@ -161,7 +171,7 @@ wot_group.add_command(status) help="Create, save, verify or publish revocation document.\n\ Subcommands optionally take the path to the revocation document.", ) -@help_option("-h", "--help") +@click.help_option("-h", "--help") def revocation_group() -> None: pass diff --git a/silkaj/money/balance.py b/silkaj/money/balance.py index 552e15b06469389a7cd98d8a44a713c5f1a1ceea..65dbf20e0c65e5efebb89781da6fb5e9b7103ef8 100644 --- a/silkaj/money/balance.py +++ b/silkaj/money/balance.py @@ -16,7 +16,7 @@ import sys from typing import List -from click import Context, argument, command, echo, pass_context +import click from silkaj import tui from silkaj.auth import auth_method, has_auth_method @@ -27,10 +27,10 @@ from silkaj.tools import get_currency_symbol from silkaj.wot import tools as wt -@command("balance", help="Get wallet balance") -@argument("pubkeys", nargs=-1) -@pass_context -def balance_cmd(ctx: Context, pubkeys: str) -> None: +@click.command("balance", help="Get wallet balance") +@click.argument("pubkeys", nargs=-1) +@click.pass_context +def balance_cmd(ctx: click.Context, pubkeys: str) -> None: if not has_auth_method(): # check input pubkeys if not pubkeys: @@ -121,7 +121,7 @@ def show_amount_from_pubkey(label: str, inputs_balance: List[int]) -> None: table = tui.Table() table.fill_rows(display) - echo(table.draw()) + click.echo(table.draw()) def get_average() -> int: diff --git a/silkaj/money/history.py b/silkaj/money/history.py index 85506e7340ddd5ef024627037bee00e2da0f5812..ca28e3a92642f44cc5cbafeaef61d0acb0cf541d 100644 --- a/silkaj/money/history.py +++ b/silkaj/money/history.py @@ -17,7 +17,7 @@ from operator import eq, itemgetter, ne, neg from typing import Any, List, Optional, Tuple from urllib.error import HTTPError -from click import argument, command, echo_via_pager, option +import click from duniterpy.api.bma.tx import history from duniterpy.api.client import Client from duniterpy.documents.transaction import OutputSource, Transaction @@ -41,10 +41,10 @@ from silkaj.tui import Table from silkaj.wot import tools as wt -@command("history", help="Display transaction history") -@argument("pubkey") -@option("--uids", "-u", is_flag=True, help="Display uids") -@option("--full-pubkey", "-f", is_flag=True, help="Display full-length pubkeys") +@click.command("history", help="Display transaction history") +@click.argument("pubkey") +@click.option("--uids", "-u", is_flag=True, help="Display uids") +@click.option("--full-pubkey", "-f", is_flag=True, help="Display full-length pubkeys") def transaction_history(pubkey: str, uids: bool, full_pubkey: bool) -> None: if check_pubkey_format(pubkey): pubkey = validate_checksum(pubkey) @@ -76,7 +76,7 @@ def transaction_history(pubkey: str, uids: bool, full_pubkey: bool) -> None: ] table = Table() table.fill_rows(txs_list, table_headers) - echo_via_pager(header + table.draw()) + click.echo_via_pager(header + table.draw()) def generate_header(pubkey: str, currency_symbol: str, ud_value: int) -> str: