# Path: mongoctl/mongoctl_logging.py
# def log_info(msg):
#     get_logger().info(msg)
# 
# Path: mongoctl/utils.py
# def to_string(thing):
#     return "" if thing is None else str(thing)


import mongoctl.repository as repository
from mongoctl.mongoctl_logging import log_info
from mongoctl.utils import to_string
__author__ = 'abdul'


###############################################################################
# list clusters command
###############################################################################
def list_clusters_command(parsed_options):
    clusters = repository.lookup_all_clusters()
    if not clusters or len(clusters) < 1:
        log_info("No clusters configured")
        return

    # sort clusters by id
    clusters = sorted(clusters, key=lambda c: c.id)
    bar = "-"*80
    print bar
    formatter = "%-25s %-40s %s"
    print formatter % ("_ID", "DESCRIPTION", "MEMBERS")
    print bar

    for cluster in clusters:

# Path: mongoctl/mongoctl_logging.py
# def log_info(msg):
#     get_logger().info(msg)
# 
# Path: mongoctl/utils.py
# def to_string(thing):
#     return "" if thing is None else str(thing)


# Path: mongoctl/commands/cluster/list_clusters.py
import mongoctl.repository as repository
from mongoctl.mongoctl_logging import log_info
from mongoctl.utils import to_string

__author__ = 'abdul'


###############################################################################
# list clusters command
###############################################################################
def list_clusters_command(parsed_options):
    clusters = repository.lookup_all_clusters()
    if not clusters or len(clusters) < 1:
        log_info("No clusters configured")
        return

    # sort clusters by id
    clusters = sorted(clusters, key=lambda c: c.id)
    bar = "-"*80
    print bar
    formatter = "%-25s %-40s %s"
    print formatter % ("_ID", "DESCRIPTION", "MEMBERS")
    print bar

    for cluster in clusters:

        desc = to_string(cluster.get_description())