Skip to content
Snippets Groups Projects
Commit 313ec872 authored by Moul's avatar Moul
Browse files

[mypy] #163: Add type annotation on checksum, cli, and cli_tools

parent 51bcc060
No related branches found
No related tags found
No related merge requests found
...@@ -35,7 +35,7 @@ MESSAGE = "You should specify a pubkey or an authentication method" ...@@ -35,7 +35,7 @@ MESSAGE = "You should specify a pubkey or an authentication method"
Can also check if the checksum is valid", Can also check if the checksum is valid",
) )
@click.argument("pubkey_checksum", nargs=-1) @click.argument("pubkey_checksum", nargs=-1)
def checksum_command(pubkey_checksum): def checksum_command(pubkey_checksum: str) -> None:
if has_auth_method(): if has_auth_method():
key = auth_method() key = auth_method()
click.echo(gen_pubkey_checksum(key.pubkey)) click.echo(gen_pubkey_checksum(key.pubkey))
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import sys import sys
from click import group, help_option, option, pass_context, version_option from click import Context, group, help_option, option, pass_context, version_option
from duniterpy.api.endpoint import endpoint from duniterpy.api.endpoint import endpoint
from silkaj import revocation from silkaj import revocation
...@@ -91,18 +91,18 @@ Do not send the document, but display it instead", ...@@ -91,18 +91,18 @@ Do not send the document, but display it instead",
) )
@pass_context @pass_context
def cli( def cli(
ctx, ctx: Context,
endpoint, endpoint: str,
gtest, gtest: bool,
auth_scrypt, auth_scrypt: bool,
nrp, nrp: str,
auth_file, auth_file: bool,
file, file: str,
auth_seed, auth_seed: bool,
auth_wif, auth_wif: bool,
display, display: bool,
dry_run, dry_run: bool,
): ) -> None:
if display and dry_run: if display and dry_run:
sys.exit("ERROR: display and dry-run options can not be used together") sys.exit("ERROR: display and dry-run options can not be used together")
...@@ -143,7 +143,7 @@ cli.add_command(received_sent_certifications) ...@@ -143,7 +143,7 @@ cli.add_command(received_sent_certifications)
Subcommands optionally take the path to the revocation document.", Subcommands optionally take the path to the revocation document.",
) )
@help_option("-h", "--help") @help_option("-h", "--help")
def revocation_group(): def revocation_group() -> None:
pass pass
...@@ -154,7 +154,7 @@ revocation_group.add_command(revocation.revoke_now) ...@@ -154,7 +154,7 @@ revocation_group.add_command(revocation.revoke_now)
@cli.command("about", help="Display program information") @cli.command("about", help="Display program information")
def about(): def about() -> None:
print( print(
"\ "\
\n @@@@@@@@@@@@@\ \n @@@@@@@@@@@@@\
......
...@@ -13,11 +13,13 @@ ...@@ -13,11 +13,13 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with Silkaj. If not, see <https://www.gnu.org/licenses/>. # along with Silkaj. If not, see <https://www.gnu.org/licenses/>.
from click import Option, UsageError from typing import Any
from click import Context, Option, UsageError
class MutuallyExclusiveOption(Option): class MutuallyExclusiveOption(Option):
def __init__(self, *args, **kwargs): def __init__(self, *args: Any, **kwargs: Any) -> None:
self.mutually_exclusive = set(kwargs.pop("mutually_exclusive", [])) self.mutually_exclusive = set(kwargs.pop("mutually_exclusive", []))
help = kwargs.get("help", "") help = kwargs.get("help", "")
if self.mutually_exclusive: if self.mutually_exclusive:
...@@ -27,7 +29,7 @@ class MutuallyExclusiveOption(Option): ...@@ -27,7 +29,7 @@ class MutuallyExclusiveOption(Option):
] = f"{help} NOTE: This argument is mutually exclusive with arguments: [{ex_str}]." ] = f"{help} NOTE: This argument is mutually exclusive with arguments: [{ex_str}]."
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
def handle_parse_result(self, ctx, opts, args): def handle_parse_result(self, ctx: Context, opts: Any, args: Any) -> Any:
if self.mutually_exclusive.intersection(opts) and self.name in opts: if self.mutually_exclusive.intersection(opts) and self.name in opts:
arguments = ", ".join(self.mutually_exclusive) arguments = ", ".join(self.mutually_exclusive)
raise UsageError( raise UsageError(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment