diff options
Diffstat (limited to 'packages/meshbay-cli/src/meshbay_cli/commands/groups.py')
| -rw-r--r-- | packages/meshbay-cli/src/meshbay_cli/commands/groups.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/packages/meshbay-cli/src/meshbay_cli/commands/groups.py b/packages/meshbay-cli/src/meshbay_cli/commands/groups.py index 7595e2b..04395dd 100644 --- a/packages/meshbay-cli/src/meshbay_cli/commands/groups.py +++ b/packages/meshbay-cli/src/meshbay_cli/commands/groups.py @@ -7,12 +7,15 @@ it. "owner" is the account that created the group on the hub — a node's operator is another notion. """ +import contextlib import json import sys from datetime import datetime from ..client.groups import my_groups +from ..client.hub import HubError from ..client.paths import handle +from ..errors import CliError from ..output import safe, sentence from .context import Context @@ -31,7 +34,7 @@ def node_state(g: dict) -> str: return "up" if g.get("node_online") else "down" -def _when(iso: str | None) -> str: +def local_time(iso: str | None) -> str: if not iso: return "" try: @@ -45,6 +48,11 @@ async def run(ctx: Context) -> int: account = ctx.account() try: groups = await my_groups(account) + waiting = 0 + if not ctx.args.json and not ctx.args.quiet: + # A hub without invitations answers nothing useful; the list stands. + with contextlib.suppress(HubError, CliError): + waiting = len(await account.call(account.hub.invitations)) finally: await account.close() groups.sort(key=lambda g: (g["name"].lower(), g.get("owner_username") or "")) @@ -58,6 +66,9 @@ async def run(ctx: Context) -> int: for g in groups], sys.stdout, indent=1) print() return 0 + if waiting: + print(f"{waiting} invitation{'s' if waiting != 1 else ''} waiting for your answer: " + "meshbay-cli invitations", file=sys.stderr) if not groups: print("You belong to no group yet.", file=sys.stderr) return 0 @@ -65,5 +76,5 @@ async def run(ctx: Context) -> int: for g in groups: role = "owner" if g.get("is_admin") else "member" print(f"{node_state(g):<6}{role:<8}{safe(g.get('visibility') or ''):<12}" - f"{_when(g.get('last_activity_at')):<18}{safe(handle(g))}") + f"{local_time(g.get('last_activity_at')):<18}{safe(handle(g))}") return 0 |