# Path: syncano_cli/config.py
# ACCOUNT_CONFIG_PATH = os.path.join(os.path.expanduser('~'), '.syncano')
# 
# Path: syncano_cli/execute/command.py
# class ExecuteCommand(BaseInstanceCommand):
# 
#     def execute(self, script_endpoint_name, data):
#         se = self.instance.script_endpoints.get(name=script_endpoint_name)
#         data = parse_input_data(data)
#         response = se.run(**data)
#         self.formatter.write('The result of the Script `{}` run is:'.format(script_endpoint_name), SpacedOpt())
#         self.print_response(response)
# 
#     def print_response(self, response):
#         if hasattr(response, 'result'):
#             if response.status == 'success':
#                 self._print_result(response.result['stdout'])
#             else:
#                 self.formatter.write(response.result['stderr'])
#         else:
#             self._print_result(response)
# 
#     def _print_result(self, result):
#         try:
#             if isinstance(result, six.string_types):
#                 output = json.loads(result)
#             else:
#                 output = result
#             self.formatter.write(json.dumps(output, indent=4, sort_keys=True), DefaultOpt(indent=2),
#                                  BottomSpacedOpt(), WarningOpt())
#         except ValueError:
#             self.formatter.write(result, DefaultOpt(indent=2), BottomSpacedOpt())


import click
from syncano_cli.config import ACCOUNT_CONFIG_PATH
from syncano_cli.execute.command import ExecuteCommand
# -*- coding: utf-8 -*-



@click.group()
def top_execute():
    pass


@top_execute.command()
@click.option('--config', help=u'Account configuration file.', default=ACCOUNT_CONFIG_PATH)
@click.option('--instance-name', help=u'Instance name.')
@click.argument('script_endpoint_name')
@click.option('-d', '--data', help=u'A data to be sent as payload: key=value', multiple=True)
def execute(config, instance_name, script_endpoint_name, data):
    """Execute Script endpoint in given Instance."""

# Path: syncano_cli/config.py
# ACCOUNT_CONFIG_PATH = os.path.join(os.path.expanduser('~'), '.syncano')
# 
# Path: syncano_cli/execute/command.py
# class ExecuteCommand(BaseInstanceCommand):
# 
#     def execute(self, script_endpoint_name, data):
#         se = self.instance.script_endpoints.get(name=script_endpoint_name)
#         data = parse_input_data(data)
#         response = se.run(**data)
#         self.formatter.write('The result of the Script `{}` run is:'.format(script_endpoint_name), SpacedOpt())
#         self.print_response(response)
# 
#     def print_response(self, response):
#         if hasattr(response, 'result'):
#             if response.status == 'success':
#                 self._print_result(response.result['stdout'])
#             else:
#                 self.formatter.write(response.result['stderr'])
#         else:
#             self._print_result(response)
# 
#     def _print_result(self, result):
#         try:
#             if isinstance(result, six.string_types):
#                 output = json.loads(result)
#             else:
#                 output = result
#             self.formatter.write(json.dumps(output, indent=4, sort_keys=True), DefaultOpt(indent=2),
#                                  BottomSpacedOpt(), WarningOpt())
#         except ValueError:
#             self.formatter.write(result, DefaultOpt(indent=2), BottomSpacedOpt())


# Path: syncano_cli/execute/commands.py
import click
from syncano_cli.config import ACCOUNT_CONFIG_PATH
from syncano_cli.execute.command import ExecuteCommand

# -*- coding: utf-8 -*-



@click.group()
def top_execute():
    pass


@top_execute.command()
@click.option('--config', help=u'Account configuration file.', default=ACCOUNT_CONFIG_PATH)
@click.option('--instance-name', help=u'Instance name.')
@click.argument('script_endpoint_name')
@click.option('-d', '--data', help=u'A data to be sent as payload: key=value', multiple=True)
def execute(config, instance_name, script_endpoint_name, data):
    """Execute Script endpoint in given Instance."""

    execute_command = ExecuteCommand(config)