Add type hints for the functions

This commit is contained in:
MasterofJOKers 2022-01-25 23:40:51 +01:00
parent c1b4851c97
commit ad7c021067
1 changed files with 9 additions and 7 deletions

View File

@ -1,14 +1,15 @@
#!/usr/bin/env python3
import difflib
import functools
from typing import Callable
import click
from clintermission import cli_select_item
import editor
from sievelib.managesieve import Client
from clintermission import cli_select_item # type: ignore
import editor # type: ignore
from sievelib.managesieve import Client # type: ignore
def default_options(f):
def default_options(f: Callable) -> Callable:
@click.option('--server', prompt=True, help='sieve server to connect to')
@click.option('-u', '--user', prompt=True, help='user to connect as')
@click.option('--password', prompt=True, hide_input=True,
@ -31,7 +32,7 @@ def main():
@default_options
@click.option('--script-name',
help='script name to set as active. If not provided, choices will be presented.')
def active(server, user, password, starttls, script_name):
def active(server: str, user: str, password: str, starttls: bool, script_name: str) -> int:
"""Connect to a SIEVE server and set a script as active"""
c = Client(server)
c.connect(user, password, starttls=starttls)
@ -45,7 +46,7 @@ def active(server, user, password, starttls, script_name):
if active == script_name:
click.echo('Script {} is already active.'.format(script_name))
return
return 0
if script_name not in scripts:
click.echo('Error: script {} cannot be found. Valid choices are: {}'
@ -53,6 +54,7 @@ def active(server, user, password, starttls, script_name):
return 1
c.setactive(script_name)
return 0
DEFAULT_TEMPLATE = """\
@ -83,7 +85,7 @@ if header :contains "To" "paypal@" {
@main.command()
@default_options
@click.option('--script-name', help='Edit this script or create it')
def edit(server, user, password, starttls, script_name):
def edit(server: str, user: str, password: str, starttls: bool, script_name: str) -> None:
"""Connect to a SIEVE server, download, edit and upload a script"""
c = Client(server)
c.connect(user, password, starttls=starttls)