# Path: jubakit/_cli/base.py
# class BaseRpcCLI(BaseCLI):
#   """
#   CLI that supports RPC commands.
#   """
# 
#   @Arguments(str, int, Optional(str))
#   def do_connect(self, host, port, cluster):
#     """Syntax: connect host port [cluster]
#     Connect to the specified host, port and cluster (optional).
#     """
#     if cluster is None:
#       cluster = self._sh._cluster
# 
#     print("Connecting to <{0}>@{1}:{2}...".format(cluster, host, port))
#     self._sh.set_remote(host, port, cluster, None)
#     raise CLIInvalidatedException()
# 
#   @Arguments()
#   def do_reconnect(self):
#     """Syntax: reconnect
#     Reconnects to the current server.
#     """
#     self._sh.connect()
#     raise CLIInvalidatedException()
# 
#   @Arguments()
#   def do_verbose(self):
#     """Syntax: verbose
#     Toggles the verbose mode.
#     """
#     self._sh._verbose = not self._sh._verbose
#     if self._sh._verbose:
#       print("Verbose mode: on")
#     else:
#       print("Verbose mode: off")
# 
#   @Arguments()
#   def do_keepalive(self):
#     """Syntax: keepalive
#     Toggles the keepalive mode.
#     """
#     self._sh._keepalive = not self._sh._keepalive
#     if self._sh._keepalive:
#       print("Keepalive: enabled")
#     else:
#       print("Keepalive: disabled")
# 
#   @Arguments(Optional(int))
#   def do_timeout(self, timeout):
#     """Syntax: timeout [new_value]
#     Displays or sets the client-side timeout.
#     """
#     if timeout is not None:
#       self._sh.set_timeout(timeout)
#     print("Timeout: {0} seconds".format(self._sh.get_timeout()))
# 
# Path: jubakit/_cli/args.py
# def Arguments(*expected_types):
#   def wrap_by_preprocessor(func):
#     assert len(inspect.getargspec(func).args) == (len(expected_types) + 1)
# 
#     def preprocessor(self, line):
#       params = shell_split(line)
#       types = []
#       (min_count, max_count) = (0, 0)
# 
#       for t in expected_types:
#         if not isinstance(t, Requirement):
#           t = Mandatory(t)
#         types.append(t)
#         (t_min, t_max) = t.min_max()
#         min_count += t_min
#         if t_max is None:
#           max_count = None
#         elif max_count is not None:
#           max_count += t_max
# 
#       params_len = len(params)
#       if params_len < min_count:
#         raise ValueError('Too few arguments ({0} required at least, only got {1})'.format(min_count, params_len))
#       if max_count is not None and max_count < params_len:
#         raise ValueError('Too many arguments ({0} required at most, got {1})'.format(max_count, params_len))
# 
#       index = 0
#       argv = []
#       for t in types:
#         try:
#           (consumed, value) = t.convert(params[index:])
#         except ValueError as e:
#           raise ValueError('argument {0}: {1}'.format(index + 1, e))
#         argv.append(value)
#         index += consumed
#       return func(self, *argv)
#     preprocessor.__doc__ = func.__doc__
#     return preprocessor
#   return wrap_by_preprocessor
# 
# Path: jubakit/_stdio.py
# @classmethod
# def print(cls, *args, **kwargs):
#   builtins.print(file=cls.stdout, *args, **kwargs)


import json
from ..base import BaseRpcCLI
from ..args import Arguments
from ..util import *
from ..._stdio import print

from __future__ import absolute_import, division, print_function, unicode_literals



class GenericCLI(BaseRpcCLI):
  """
  Base CLI implementation for all other services.
  """

  def __init__(self, *args, **kwargs):
    super(GenericCLI, self).__init__(*args, **kwargs)
    self._clear_cache()

  @classmethod
  def _name(cls):
    return 'generic'

  def _clear_cache(self):
    """
    Subclasses using cache must override this method; initialize or invalidate
    cache when this method is called.
    """
    pass

  def _print_status(self, status):
    """
    Pretty-print the status structure.
    """
    for (host_port, status) in status.items():

# Path: jubakit/_cli/base.py
# class BaseRpcCLI(BaseCLI):
#   """
#   CLI that supports RPC commands.
#   """
# 
#   @Arguments(str, int, Optional(str))
#   def do_connect(self, host, port, cluster):
#     """Syntax: connect host port [cluster]
#     Connect to the specified host, port and cluster (optional).
#     """
#     if cluster is None:
#       cluster = self._sh._cluster
# 
#     print("Connecting to <{0}>@{1}:{2}...".format(cluster, host, port))
#     self._sh.set_remote(host, port, cluster, None)
#     raise CLIInvalidatedException()
# 
#   @Arguments()
#   def do_reconnect(self):
#     """Syntax: reconnect
#     Reconnects to the current server.
#     """
#     self._sh.connect()
#     raise CLIInvalidatedException()
# 
#   @Arguments()
#   def do_verbose(self):
#     """Syntax: verbose
#     Toggles the verbose mode.
#     """
#     self._sh._verbose = not self._sh._verbose
#     if self._sh._verbose:
#       print("Verbose mode: on")
#     else:
#       print("Verbose mode: off")
# 
#   @Arguments()
#   def do_keepalive(self):
#     """Syntax: keepalive
#     Toggles the keepalive mode.
#     """
#     self._sh._keepalive = not self._sh._keepalive
#     if self._sh._keepalive:
#       print("Keepalive: enabled")
#     else:
#       print("Keepalive: disabled")
# 
#   @Arguments(Optional(int))
#   def do_timeout(self, timeout):
#     """Syntax: timeout [new_value]
#     Displays or sets the client-side timeout.
#     """
#     if timeout is not None:
#       self._sh.set_timeout(timeout)
#     print("Timeout: {0} seconds".format(self._sh.get_timeout()))
# 
# Path: jubakit/_cli/args.py
# def Arguments(*expected_types):
#   def wrap_by_preprocessor(func):
#     assert len(inspect.getargspec(func).args) == (len(expected_types) + 1)
# 
#     def preprocessor(self, line):
#       params = shell_split(line)
#       types = []
#       (min_count, max_count) = (0, 0)
# 
#       for t in expected_types:
#         if not isinstance(t, Requirement):
#           t = Mandatory(t)
#         types.append(t)
#         (t_min, t_max) = t.min_max()
#         min_count += t_min
#         if t_max is None:
#           max_count = None
#         elif max_count is not None:
#           max_count += t_max
# 
#       params_len = len(params)
#       if params_len < min_count:
#         raise ValueError('Too few arguments ({0} required at least, only got {1})'.format(min_count, params_len))
#       if max_count is not None and max_count < params_len:
#         raise ValueError('Too many arguments ({0} required at most, got {1})'.format(max_count, params_len))
# 
#       index = 0
#       argv = []
#       for t in types:
#         try:
#           (consumed, value) = t.convert(params[index:])
#         except ValueError as e:
#           raise ValueError('argument {0}: {1}'.format(index + 1, e))
#         argv.append(value)
#         index += consumed
#       return func(self, *argv)
#     preprocessor.__doc__ = func.__doc__
#     return preprocessor
#   return wrap_by_preprocessor
# 
# Path: jubakit/_stdio.py
# @classmethod
# def print(cls, *args, **kwargs):
#   builtins.print(file=cls.stdout, *args, **kwargs)


# Path: jubakit/_cli/service/generic.py
import json
from ..base import BaseRpcCLI
from ..args import Arguments
from ..util import *
from ..._stdio import print


from __future__ import absolute_import, division, print_function, unicode_literals



class GenericCLI(BaseRpcCLI):
  """
  Base CLI implementation for all other services.
  """

  def __init__(self, *args, **kwargs):
    super(GenericCLI, self).__init__(*args, **kwargs)
    self._clear_cache()

  @classmethod
  def _name(cls):
    return 'generic'

  def _clear_cache(self):
    """
    Subclasses using cache must override this method; initialize or invalidate
    cache when this method is called.
    """
    pass

  def _print_status(self, status):
    """
    Pretty-print the status structure.
    """
    for (host_port, status) in status.items():

      print("Server {0}:{1}".format(*(host_port.split('_'))))