pivotalcli/util.py

35 lines
848 B
Python

import commands.login
import shutil
import textwrap
from typing import Any, Callable
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:
while 'api_token' not in Config['user']:
commands.login.login(None)
return function(*args, **kwargs)
return wrapper