2018-04-03 10:56:07 +00:00
|
|
|
import shutil
|
|
|
|
import textwrap
|
2019-02-05 12:39:50 +00:00
|
|
|
from commands.login import login
|
2018-08-17 14:26:46 +00:00
|
|
|
from typing import Any, Callable
|
2018-04-03 10:56:07 +00:00
|
|
|
|
|
|
|
from config import Config
|
|
|
|
|
|
|
|
|
|
|
|
def print_wrap(text: str, indent: str = '', end: str = '\n') -> None:
|
|
|
|
w, _ = shutil.get_terminal_size((80, 20))
|
|
|
|
if w > 72:
|
|
|
|
w = 72
|
|
|
|
|
|
|
|
lines = text.split('\n')
|
|
|
|
for i, line in enumerate(lines):
|
|
|
|
_end = '\n' if i < len(lines) - 1 else end
|
|
|
|
|
|
|
|
if not line:
|
|
|
|
print(indent, end=_end)
|
|
|
|
continue
|
|
|
|
|
|
|
|
wrapped = textwrap.fill(
|
|
|
|
line, w, initial_indent=indent, subsequent_indent=indent)
|
|
|
|
print(wrapped, end=_end)
|
|
|
|
|
|
|
|
|
|
|
|
def require_login(function: Callable) -> Callable:
|
|
|
|
def wrapper(*args: Any, **kwargs: Any) -> Any:
|
2019-02-05 12:39:50 +00:00
|
|
|
if 'api_token' not in Config['user']:
|
2018-08-17 14:27:26 +00:00
|
|
|
print('Not logged in. Please use the login command to log in.')
|
2019-02-05 12:39:50 +00:00
|
|
|
return
|
2018-04-03 10:56:07 +00:00
|
|
|
|
|
|
|
return function(*args, **kwargs)
|
|
|
|
|
|
|
|
return wrapper
|