Add type hints for the functions
This commit is contained in:
parent
c1b4851c97
commit
ad7c021067
16
sievedit.py
16
sievedit.py
|
@ -1,14 +1,15 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import difflib
|
import difflib
|
||||||
import functools
|
import functools
|
||||||
|
from typing import Callable
|
||||||
|
|
||||||
import click
|
import click
|
||||||
from clintermission import cli_select_item
|
from clintermission import cli_select_item # type: ignore
|
||||||
import editor
|
import editor # type: ignore
|
||||||
from sievelib.managesieve import Client
|
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('--server', prompt=True, help='sieve server to connect to')
|
||||||
@click.option('-u', '--user', prompt=True, help='user to connect as')
|
@click.option('-u', '--user', prompt=True, help='user to connect as')
|
||||||
@click.option('--password', prompt=True, hide_input=True,
|
@click.option('--password', prompt=True, hide_input=True,
|
||||||
|
@ -31,7 +32,7 @@ def main():
|
||||||
@default_options
|
@default_options
|
||||||
@click.option('--script-name',
|
@click.option('--script-name',
|
||||||
help='script name to set as active. If not provided, choices will be presented.')
|
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"""
|
"""Connect to a SIEVE server and set a script as active"""
|
||||||
c = Client(server)
|
c = Client(server)
|
||||||
c.connect(user, password, starttls=starttls)
|
c.connect(user, password, starttls=starttls)
|
||||||
|
@ -45,7 +46,7 @@ def active(server, user, password, starttls, script_name):
|
||||||
|
|
||||||
if active == script_name:
|
if active == script_name:
|
||||||
click.echo('Script {} is already active.'.format(script_name))
|
click.echo('Script {} is already active.'.format(script_name))
|
||||||
return
|
return 0
|
||||||
|
|
||||||
if script_name not in scripts:
|
if script_name not in scripts:
|
||||||
click.echo('Error: script {} cannot be found. Valid choices are: {}'
|
click.echo('Error: script {} cannot be found. Valid choices are: {}'
|
||||||
|
@ -53,6 +54,7 @@ def active(server, user, password, starttls, script_name):
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
c.setactive(script_name)
|
c.setactive(script_name)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_TEMPLATE = """\
|
DEFAULT_TEMPLATE = """\
|
||||||
|
@ -83,7 +85,7 @@ if header :contains "To" "paypal@" {
|
||||||
@main.command()
|
@main.command()
|
||||||
@default_options
|
@default_options
|
||||||
@click.option('--script-name', help='Edit this script or create it')
|
@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"""
|
"""Connect to a SIEVE server, download, edit and upload a script"""
|
||||||
c = Client(server)
|
c = Client(server)
|
||||||
c.connect(user, password, starttls=starttls)
|
c.connect(user, password, starttls=starttls)
|
||||||
|
|
Loading…
Reference in New Issue