# Path: contrail_api_cli/command.py
# class Command(object):
#     """Base class for commands
#     """
#     description = ""
#     """Description of the command"""
#     aliases = []
#     """Command aliases"""
#     _options = None
#     _args = None
# 
#     def __init__(self, name):
#         self.parser = ArgumentParser(prog=name, description=self.description)
#         self.add_arguments_to_parser(self.parser)
#         self._is_piped = False
# 
#     def current_path(self, resource):
#         """Return current path for resource
# 
#         :param resource: resource or collection
#         :type resource: Resource|Collection
# 
#         :rtype: str
#         """
#         return text_type(resource.path.relative_to(Context().shell.current_path))
# 
#     @property
#     def is_piped(self):
#         """Return True if the command result is beeing piped
#         to another command.
# 
#         :rtype: bool
#         """
#         return not sys.stdout.isatty() or self._is_piped
# 
#     @is_piped.setter
#     def is_piped(self, value):
#         self._is_piped = value
# 
#     @classproperty
#     def options(cls):
#         if cls._options is not None:
#             return cls._options
#         cls._options = OrderedDict()
#         for attr, option in sorted(
#                 inspect.getmembers(cls, lambda o: isinstance(o, Option)),
#                 key=lambda i: i[1]._creation_idx):
#             option.attr = attr
#             cls._options[text_type(attr)] = option
#         return cls._options
# 
#     @classproperty
#     def args(cls):
#         if cls._args is not None:
#             return cls._args
#         cls._args = OrderedDict()
#         for attr, arg in sorted(
#                 inspect.getmembers(cls, lambda o: isinstance(o, Arg)),
#                 key=lambda i: i[1]._creation_idx):
#             arg.attr = attr
#             cls._args[text_type(attr)] = arg
#         return cls._args
# 
#     @classmethod
#     def add_arguments_to_parser(cls, parser):
#         for (arg_name, arg) in cls.args.items():
#             parser.add_argument(arg_name, **arg.kwargs)
#         for (option_name, option) in cls.options.items():
#             parser.add_argument(*option.option_strings, **option.kwargs)
# 
#     def parse_and_call(self, *args):
#         args = self.parser.parse_args(args=args)
#         return self.__call__(**vars(args))
# 
#     @abc.abstractmethod
#     def __call__(self, **kwargs):
#         """Command must implement this method.
# 
#         The command must return an unicode string
#         (unicode in python2 or str in python3)
# 
#         :param kwargs: options of the command
# 
#         :rtype: unicode | str
#         """
# 
# class Option(BaseOption):
# 
#     def __init__(self, short_name=None, **kwargs):
#         BaseOption.__init__(self, **kwargs)
#         self.short_name = short_name
# 
#     @property
#     def need_value(self):
#         return self.kwargs.get('action') not in ('store_true', 'store_false')
# 
#     @property
#     def long_name(self):
#         return '--%s' % self.attr.replace('_', '-')
# 
#     @property
#     def option_strings(self):
#         return [n for n in (self.long_name, self.short_name) if n is not None]
# 
# Path: contrail_api_cli/utils.py
# def to_json(resource_dict, cls=None):
#     return json.dumps(resource_dict,
#                       indent=2,
#                       sort_keys=True,
#                       skipkeys=True,
#                       cls=cls)
# 
# def highlight_json(json_data):
#     return highlight(json_data,
#                      JsonLexer(indent=2),
#                      Terminal256Formatter(bg="dark"))
# 
# Path: contrail_api_cli/context.py
# class Context(object):
#     _schema = None
#     _shell = ShellContext
#     _session = None
# 
#     @property
#     def schema(self):
#         if self._schema is None:
#             raise SchemaNotInitialized("The schema must be first initialized")
#         else:
#             return self._schema
# 
#     @schema.setter
#     def schema(self, schema):
#         self._schema = schema
# 
#     @property
#     def session(self):
#         if self._session is None:
#             raise SessionNotInitialized("The session must be first initialized")
#         else:
#             return self._session
# 
#     @session.setter
#     def session(self, session):
#         self._session = session
# 
#     @property
#     def shell(self):
#         return self._shell


from ..command import Command, Option
from ..utils import to_json, highlight_json
from ..context import Context
        admin@localhost:/> kv --add my-key my-value
        admin@localhost:/> kv --get my-key
        [
          {
            "key": "my-key",
            "value": "my-value"
          }
        ]

        admin@localhost:/> kv --delete my-key
        admin@localhost:/> kv --get my-key
        Unknown User-Agent key my-key (HTTP 404)
    """
    description = "Retrieve the key-value store as json"

    delete = Option("-D", type=str, metavar='key',
                    help="Delete key entry")
    add = Option("-a", nargs=2, metavar=('key', 'value'),
                 help="Add a key and a value")
    get = Option("-g", type=str, metavar='key',
                 help="Get a entry from a key")
    list_all = Option("-l", action="store_true",
                      default=False,
                      help="List all entries")

    def __call__(self, add=None, delete=None, list_all=False, get=None):
        if add is not None:
            Context().session.add_kv_store(add[0], add[1])
            return None
        elif delete is not None:

# Path: contrail_api_cli/command.py
# class Command(object):
#     """Base class for commands
#     """
#     description = ""
#     """Description of the command"""
#     aliases = []
#     """Command aliases"""
#     _options = None
#     _args = None
# 
#     def __init__(self, name):
#         self.parser = ArgumentParser(prog=name, description=self.description)
#         self.add_arguments_to_parser(self.parser)
#         self._is_piped = False
# 
#     def current_path(self, resource):
#         """Return current path for resource
# 
#         :param resource: resource or collection
#         :type resource: Resource|Collection
# 
#         :rtype: str
#         """
#         return text_type(resource.path.relative_to(Context().shell.current_path))
# 
#     @property
#     def is_piped(self):
#         """Return True if the command result is beeing piped
#         to another command.
# 
#         :rtype: bool
#         """
#         return not sys.stdout.isatty() or self._is_piped
# 
#     @is_piped.setter
#     def is_piped(self, value):
#         self._is_piped = value
# 
#     @classproperty
#     def options(cls):
#         if cls._options is not None:
#             return cls._options
#         cls._options = OrderedDict()
#         for attr, option in sorted(
#                 inspect.getmembers(cls, lambda o: isinstance(o, Option)),
#                 key=lambda i: i[1]._creation_idx):
#             option.attr = attr
#             cls._options[text_type(attr)] = option
#         return cls._options
# 
#     @classproperty
#     def args(cls):
#         if cls._args is not None:
#             return cls._args
#         cls._args = OrderedDict()
#         for attr, arg in sorted(
#                 inspect.getmembers(cls, lambda o: isinstance(o, Arg)),
#                 key=lambda i: i[1]._creation_idx):
#             arg.attr = attr
#             cls._args[text_type(attr)] = arg
#         return cls._args
# 
#     @classmethod
#     def add_arguments_to_parser(cls, parser):
#         for (arg_name, arg) in cls.args.items():
#             parser.add_argument(arg_name, **arg.kwargs)
#         for (option_name, option) in cls.options.items():
#             parser.add_argument(*option.option_strings, **option.kwargs)
# 
#     def parse_and_call(self, *args):
#         args = self.parser.parse_args(args=args)
#         return self.__call__(**vars(args))
# 
#     @abc.abstractmethod
#     def __call__(self, **kwargs):
#         """Command must implement this method.
# 
#         The command must return an unicode string
#         (unicode in python2 or str in python3)
# 
#         :param kwargs: options of the command
# 
#         :rtype: unicode | str
#         """
# 
# class Option(BaseOption):
# 
#     def __init__(self, short_name=None, **kwargs):
#         BaseOption.__init__(self, **kwargs)
#         self.short_name = short_name
# 
#     @property
#     def need_value(self):
#         return self.kwargs.get('action') not in ('store_true', 'store_false')
# 
#     @property
#     def long_name(self):
#         return '--%s' % self.attr.replace('_', '-')
# 
#     @property
#     def option_strings(self):
#         return [n for n in (self.long_name, self.short_name) if n is not None]
# 
# Path: contrail_api_cli/utils.py
# def to_json(resource_dict, cls=None):
#     return json.dumps(resource_dict,
#                       indent=2,
#                       sort_keys=True,
#                       skipkeys=True,
#                       cls=cls)
# 
# def highlight_json(json_data):
#     return highlight(json_data,
#                      JsonLexer(indent=2),
#                      Terminal256Formatter(bg="dark"))
# 
# Path: contrail_api_cli/context.py
# class Context(object):
#     _schema = None
#     _shell = ShellContext
#     _session = None
# 
#     @property
#     def schema(self):
#         if self._schema is None:
#             raise SchemaNotInitialized("The schema must be first initialized")
#         else:
#             return self._schema
# 
#     @schema.setter
#     def schema(self, schema):
#         self._schema = schema
# 
#     @property
#     def session(self):
#         if self._session is None:
#             raise SessionNotInitialized("The session must be first initialized")
#         else:
#             return self._session
# 
#     @session.setter
#     def session(self, session):
#         self._session = session
# 
#     @property
#     def shell(self):
#         return self._shell


# Path: contrail_api_cli/commands/kv.py
from ..command import Command, Option
from ..utils import to_json, highlight_json
from ..context import Context

        admin@localhost:/> kv --add my-key my-value
        admin@localhost:/> kv --get my-key
        [
          {
            "key": "my-key",
            "value": "my-value"
          }
        ]

        admin@localhost:/> kv --delete my-key
        admin@localhost:/> kv --get my-key
        Unknown User-Agent key my-key (HTTP 404)
    """
    description = "Retrieve the key-value store as json"

    delete = Option("-D", type=str, metavar='key',
                    help="Delete key entry")
    add = Option("-a", nargs=2, metavar=('key', 'value'),
                 help="Add a key and a value")
    get = Option("-g", type=str, metavar='key',
                 help="Get a entry from a key")
    list_all = Option("-l", action="store_true",
                      default=False,
                      help="List all entries")

    def __call__(self, add=None, delete=None, list_all=False, get=None):
        if add is not None:
            Context().session.add_kv_store(add[0], add[1])
            return None
        elif delete is not None:

            Context().session.remove_kv_store(delete)