mirror of
https://github.com/ihabunek/toot
synced 2025-02-09 16:48:39 +01:00
Make list printing not break on akkoma
This commit is contained in:
parent
f324aa119d
commit
1709a416b3
@ -3,6 +3,7 @@ import json as pyjson
|
|||||||
|
|
||||||
from toot import api, config
|
from toot import api, config
|
||||||
from toot.cli import Context, cli, pass_context, json_option
|
from toot.cli import Context, cli, pass_context, json_option
|
||||||
|
from toot.entities import from_dict_list, List
|
||||||
from toot.output import print_list_accounts, print_lists, print_warning
|
from toot.output import print_list_accounts, print_lists, print_warning
|
||||||
|
|
||||||
|
|
||||||
@ -18,7 +19,8 @@ def lists(ctx: click.Context):
|
|||||||
if not user or not app:
|
if not user or not app:
|
||||||
raise click.ClickException("This command requires you to be logged in.")
|
raise click.ClickException("This command requires you to be logged in.")
|
||||||
|
|
||||||
lists = api.get_lists(app, user)
|
data = api.get_lists(app, user)
|
||||||
|
lists = from_dict_list(List, data)
|
||||||
if lists:
|
if lists:
|
||||||
print_lists(lists)
|
print_lists(lists)
|
||||||
else:
|
else:
|
||||||
@ -30,12 +32,13 @@ def lists(ctx: click.Context):
|
|||||||
@pass_context
|
@pass_context
|
||||||
def list(ctx: Context, json: bool):
|
def list(ctx: Context, json: bool):
|
||||||
"""List all your lists"""
|
"""List all your lists"""
|
||||||
lists = api.get_lists(ctx.app, ctx.user)
|
data = api.get_lists(ctx.app, ctx.user)
|
||||||
|
|
||||||
if json:
|
if json:
|
||||||
click.echo(pyjson.dumps(lists))
|
click.echo(pyjson.dumps(data))
|
||||||
else:
|
else:
|
||||||
if lists:
|
if data:
|
||||||
|
lists = from_dict_list(List, data)
|
||||||
print_lists(lists)
|
print_lists(lists)
|
||||||
else:
|
else:
|
||||||
click.echo("You have no lists defined.")
|
click.echo("You have no lists defined.")
|
||||||
|
@ -4,7 +4,7 @@ import shutil
|
|||||||
import textwrap
|
import textwrap
|
||||||
import typing as t
|
import typing as t
|
||||||
|
|
||||||
from toot.entities import Account, Instance, Notification, Poll, Status
|
from toot.entities import Account, Instance, Notification, Poll, Status, List
|
||||||
from toot.utils import get_text, html_to_paragraphs
|
from toot.utils import get_text, html_to_paragraphs
|
||||||
from toot.wcstring import wc_wrap
|
from toot.wcstring import wc_wrap
|
||||||
from wcwidth import wcswidth
|
from wcwidth import wcswidth
|
||||||
@ -119,9 +119,9 @@ def print_tag_list(tags):
|
|||||||
click.echo(f"* {format_tag_name(tag)}\t{tag['url']}")
|
click.echo(f"* {format_tag_name(tag)}\t{tag['url']}")
|
||||||
|
|
||||||
|
|
||||||
def print_lists(lists):
|
def print_lists(lists: t.List[List]):
|
||||||
headers = ["ID", "Title", "Replies"]
|
headers = ["ID", "Title", "Replies"]
|
||||||
data = [[lst["id"], lst["title"], lst["replies_policy"]] for lst in lists]
|
data = [[lst.id, lst.title, lst.replies_policy or ""] for lst in lists]
|
||||||
print_table(headers, data)
|
print_table(headers, data)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user