# 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 Arg(BaseOption):
#     pass


import argparse
from ..command import Command, Arg
# -*- coding: utf-8 -*-
from __future__ import unicode_literals



class Exec(Command):
    """Run python script inside the cli context.

    The script content is executed using `exec` python
    builtin.

    All script arguments can be accessed from the args
    variable inside the script::

        contrail-api-cli exec test.py arg1 arg2

    Inside the script args will be ['arg1', 'arg2'].

    This method is used to write quick debugging scripts,
    if you need a complete handling of arguments or options
    consider to write a proper command.
    """
    description = "Run a python script inside the cli"
    script = Arg(help="script path to run",
                 type=argparse.FileType('r'))

# 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 Arg(BaseOption):
#     pass


# Path: contrail_api_cli/commands/exec.py
import argparse
from ..command import Command, Arg

# -*- coding: utf-8 -*-
from __future__ import unicode_literals



class Exec(Command):
    """Run python script inside the cli context.

    The script content is executed using `exec` python
    builtin.

    All script arguments can be accessed from the args
    variable inside the script::

        contrail-api-cli exec test.py arg1 arg2

    Inside the script args will be ['arg1', 'arg2'].

    This method is used to write quick debugging scripts,
    if you need a complete handling of arguments or options
    consider to write a proper command.
    """
    description = "Run a python script inside the cli"
    script = Arg(help="script path to run",
                 type=argparse.FileType('r'))

    script_args = Arg(help="script args",