import dnsbl
import logging
import os
+import rich.console
+import rich.table
import sys
# i18n
from dnsbl.i18n import _
class CLI(object):
+ def __init__(self):
+ # Initialize the console
+ self.console = rich.console.Console()
+
def parse_cli(self):
"""
Main Function.
help=_("The license of the list"))
list_create.set_defaults(func=self.__list_create)
+ # list-show
+ list_show = subparsers.add_parser("list-show", help=_("Shows details about a list"))
+ list_show.add_argument("list", help=_("The name of the list"))
+ list_show.set_defaults(func=self.__list_show)
+
# list-add-source
list_add_source = subparsers.add_parser("list-add-source",
help=_("Creates a new source to a list"))
license = args.license,
)
+ def __list_show(self, backend, args):
+ """
+ Shows information about a list
+ """
+ list = backend.lists.get_by_slug(args.list)
+
+ table = rich.table.Table(title=list.name)
+ table.add_column(_("Property"))
+ table.add_column(_("Value"))
+
+ table.add_row(_("Name"), list.name)
+ table.add_row(_("License"), list.license)
+ table.add_row(_("Created At"), list.created_at.isoformat())
+ table.add_row(_("Created By"), list.created_by)
+
+ # Print list properties
+ self.console.print(table)
+
+ # Show all sources
+ table = rich.table.Table(title=_("Sources"))
+ table.add_column(_("Name"))
+ table.add_column(_("License"))
+ table.add_column(_("URL"))
+ table.add_column(_("Created At"))
+ table.add_column(_("Created_By"))
+
+ for source in list.sources:
+ table.add_row(
+ source.name,
+ source.license,
+ source.url,
+ source.created_at.isoformat(),
+ source.created_by,
+ )
+
+ # Print the sources
+ self.console.print(table)
+
def __list_add_source(self, backend, args):
"""
Adds a new source to a list