Skip to content

Commit

Permalink
feat: list bots by network
Browse files Browse the repository at this point in the history
  • Loading branch information
dtdang committed Jan 10, 2025
1 parent d99cc72 commit 05d1505
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions silverback/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@
)

if TYPE_CHECKING:
from typing import Dict, List

from ape.api.accounts import AccountAPI
from ape.api.networks import NetworkAPI
from ape.contracts import ContractInstance
from fief_client.integrations.cli import FiefAuth

from silverback.cluster.client import ClusterClient, PlatformClient
from silverback.cluster.client import Bot, ClusterClient, PlatformClient
from silverback.cluster.types import VariableGroupInfo

LOCAL_DATETIME = "%Y-%m-%d %H:%M:%S %Z"
Expand Down Expand Up @@ -1060,8 +1062,34 @@ def new_bot(
def list_bots(cluster: "ClusterClient"):
"""List all bots in a CLUSTER (Regardless of status)"""

if bot_names := list(cluster.bots):
click.echo(yaml.safe_dump(bot_names))
if bot_names := cluster.bots:
grouped_bots: Dict[str, Dict[str, List[Bot]]] = {}
for bot in bot_names.values():
ecosystem, network, provider = bot.network.split("-")
if ecosystem not in grouped_bots:
grouped_bots[ecosystem] = {}
network_key = f"{network}-{provider}"
if network_key not in grouped_bots[ecosystem]:
grouped_bots[ecosystem][network_key] = []
grouped_bots[ecosystem][network_key].append(bot)

sorted_ecosystem = sorted(grouped_bots.keys())
for ecosystem in sorted_ecosystem:
sorted_networks = sorted(grouped_bots[ecosystem].keys())
grouped_bots[ecosystem] = {
network: sorted(grouped_bots[ecosystem][network], key=lambda b: b.name)
for network in sorted_networks
}

output = ""
for ecosystem in sorted_ecosystem:
output += f"{ecosystem}:\n"
for network in grouped_bots[ecosystem]:
output += f" {network}:\n"
for bot in grouped_bots[ecosystem][network]:
output += f" - {bot.name}\n"

click.echo(output)

else:
click.secho("No bots in this cluster", bold=True, fg="red")
Expand Down

0 comments on commit 05d1505

Please sign in to comment.