Skip to content
Snippets Groups Projects
Commit 0239c294 authored by Moul's avatar Moul
Browse files

Import top-level click (#466)

parent 4daefaba
No related branches found
No related tags found
1 merge request!241Use rich_click (#466)
......@@ -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,
......
......@@ -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(
......
......@@ -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
......
......@@ -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:
......
......@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment