1
|
|
|
import sys |
2
|
|
|
|
3
|
|
|
import click |
4
|
|
|
import log |
5
|
|
|
|
6
|
|
|
from . import __version__, slack |
7
|
|
|
from .config import settings |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
@click.command(help="Automatically sign out/in of a Slack workspace.") |
11
|
|
|
@click.argument("workspace", nargs=-1) |
12
|
|
|
@click.option( |
13
|
|
|
"--toggle/--no-toggle", |
14
|
|
|
default=True, |
15
|
|
|
help="Sign in if already signed out.", |
16
|
|
|
) |
17
|
|
|
@click.option("--activate/--no-activate", default=True, hidden=True) |
18
|
|
|
@click.option("--debug/--no-debug", default=False, help="Show verbose logging output.") |
19
|
|
|
@click.version_option(__version__) |
20
|
|
|
def main(workspace: str, activate: bool, toggle: bool, debug: bool): |
21
|
|
|
log.init(debug=debug, format="%(levelname)s: %(message)s") |
22
|
|
|
|
23
|
|
|
if activate and not slack.activate(): |
24
|
|
|
click.echo("Unable to automate Slack") |
25
|
|
|
sys.exit(1) |
26
|
|
|
|
27
|
|
|
workspace = get_workspace(workspace) |
28
|
|
|
|
29
|
|
|
if slack.signout(workspace): |
30
|
|
|
click.echo(f"Signed out of {workspace}") |
31
|
|
|
sys.exit(0) |
32
|
|
|
|
33
|
|
|
click.echo(f"Already signed out of {workspace}") |
34
|
|
|
if toggle: |
35
|
|
|
slack.signin(workspace) |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
def get_workspace(workspace): |
39
|
|
|
workspace = " ".join(workspace) |
40
|
|
|
if not workspace: |
41
|
|
|
if settings.workspaces: |
42
|
|
|
workspace = settings.workspaces[0] |
43
|
|
|
else: |
44
|
|
|
workspace = click.prompt("Slack workspace") |
45
|
|
|
settings.workspaces = [workspace] |
46
|
|
|
return workspace |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
if __name__ == "__main__": # pragma: no cover |
50
|
|
|
main() # pylint: disable=no-value-for-parameter |
51
|
|
|
|