# Path: aeriscloud/cli/helpers.py
# class Command(click.Command):
#     # This is inherited by the Context to switch between pure POSIX and
#     # argparse-like argument parsing. Setting it to false will push any
#     # unknown flag to the argument located where the flag was declared
#     allow_interspersed_args = config.get('config', 'posix', default=False)
# 
#     def __init__(self, *args, **kwargs):
#         cs = dict(help_option_names=['-h', '--help'])
#         super(Command, self).__init__(context_settings=cs,
#                                       *args, **kwargs)
# 
# def standard_options(multiple=False, start_prompt=True):
#     """
#     Add the standard --project and --box options to a command
#     :param multiple: Whether to find a single or multiple boxes
#     :param start_prompt: When using single boxes, ask the user to start it if
#                          offline
#     """
#     if multiple:
#         return _multi_box_decorator
#     else:
#         return _single_box_decorator(start_prompt)
# 
# def error(text, **kwargs):
#     click.secho(text, fg='red', err=True, **kwargs)
# 
# def fatal(text, code=1, **kwargs):
#     error(text, **kwargs)
#     sys.exit(code)
# 
# def info(text, **kwargs):
#     click.secho(text, fg='cyan', **kwargs)
# 
# def success(text, **kwargs):
#     click.secho(text, fg='green', **kwargs)
# 
# def bold(text, **kwargs):
#     return click.style(text, bold=True, **kwargs)
# 
# Path: aeriscloud/utils.py
# def local_ip():
#     """
#     Retrieve the first ip from the interface linked to the default route
# 
#     :return str
#     """
#     sys_name = system()
#     if sys_name == 'Darwin':
#         # OSX
#         route = Command('route')
#         ifconfig = Command('ifconfig')
# 
#         iface = [
#             line.strip()
#             for line in route('-n', 'get', 'default')
#             if line.strip().startswith('interface')
#         ][0].split(':')[1].strip()
#         return [
#             line.strip()
#             for line in ifconfig(iface)
#             if line.strip().startswith('inet ')
#         ][0].split(' ')[1]
#     elif sys_name == 'Linux':
#         try:
#             ip = Command('ip')
#             iface = [
#                 line.strip()
#                 for line in ip('route')
#                 if line.strip().startswith('default ')
#             ][0].split(' ')[4]
#         except CommandNotFound:
#             route = Command('route')
#             iface = [
#                 line.strip()
#                 for line in route('-n')
#                 if line.startswith('0.0.0.0')
#             ][0].split(' ').pop()
# 
#         try:
#             # try with IP
#             ip = Command('ip')
#             return [
#                 line.strip()
#                 for line in ip('addr', 'show', iface)
#                 if line.strip().startswith('inet ')
#             ][0].split(' ')[1].split('/')[0]
#         except CommandNotFound:
#             pass
# 
#         # fallback to ifconfig
#         ifconfig = Command('ifconfig')
#         return [
#             line.strip()
#             for line in ifconfig(iface)
#             if line.strip().startswith('inet ')
#         ][0].split(' ')[1]
# 
#     return None
# 
# def quote(s):
#     """Return a shell-escaped version of the string *s*."""
#     if not s:
#         return "''"
#     if _find_unsafe(s) is None:
#         return s
# 
#     # use single quotes, and put single quotes into double quotes
#     # the string $'b is then quoted as '$'"'"'b'
#     return "'" + s.replace("'", "'\"'\"'") + "'"


import click
import os
import re
import subprocess32
import sys
from aeriscloud.cli.helpers import Command, standard_options, \
    error, fatal, info, success, bold
from aeriscloud.utils import local_ip, quote
              "-executeMethod {method} " \
              "-logFile ./build.log " \
              "-projectPath {current_dir}" \
        .format(unity_path=quote(unity_path),
                method=methods[platform],
                current_dir=quote(os.getcwd()))
    info("""The following command will be executed:
{0}.""".format(bold(command)))
    returncode = subprocess32.call(command, shell=True)
    if returncode != 0:
        error("An error occurred, please check the content "
              "of the {0} log file.".format(bold('build.log')))
        sys.exit(returncode)

    if platform == 'ios':
        os.chdir(os.path.join(os.getcwd(), 'Build', 'iPhone'))
        command = "xcodebuild -scheme Unity-iPhone archive " \
                  "-archivePath Unity-iPhone.xcarchive"
        info("""The following command will be executed:
{0}.""".format(bold(command)))
        subprocess32.check_call(command, shell=True)
        command = "xcodebuild -exportArchive " \
                  "-exportFormat ipa " \
                  "-archivePath \"Unity-iPhone.xcarchive\" " \
                  "-exportPath \"Unity-iPhone.ipa\" " \
                  "-exportProvisioningProfile \"wildcard_Development\""
        info("""The following command will be executed:
{0}.""".format(bold(command)))
        subprocess32.check_call(command, shell=True)


# Path: aeriscloud/cli/helpers.py
# class Command(click.Command):
#     # This is inherited by the Context to switch between pure POSIX and
#     # argparse-like argument parsing. Setting it to false will push any
#     # unknown flag to the argument located where the flag was declared
#     allow_interspersed_args = config.get('config', 'posix', default=False)
# 
#     def __init__(self, *args, **kwargs):
#         cs = dict(help_option_names=['-h', '--help'])
#         super(Command, self).__init__(context_settings=cs,
#                                       *args, **kwargs)
# 
# def standard_options(multiple=False, start_prompt=True):
#     """
#     Add the standard --project and --box options to a command
#     :param multiple: Whether to find a single or multiple boxes
#     :param start_prompt: When using single boxes, ask the user to start it if
#                          offline
#     """
#     if multiple:
#         return _multi_box_decorator
#     else:
#         return _single_box_decorator(start_prompt)
# 
# def error(text, **kwargs):
#     click.secho(text, fg='red', err=True, **kwargs)
# 
# def fatal(text, code=1, **kwargs):
#     error(text, **kwargs)
#     sys.exit(code)
# 
# def info(text, **kwargs):
#     click.secho(text, fg='cyan', **kwargs)
# 
# def success(text, **kwargs):
#     click.secho(text, fg='green', **kwargs)
# 
# def bold(text, **kwargs):
#     return click.style(text, bold=True, **kwargs)
# 
# Path: aeriscloud/utils.py
# def local_ip():
#     """
#     Retrieve the first ip from the interface linked to the default route
# 
#     :return str
#     """
#     sys_name = system()
#     if sys_name == 'Darwin':
#         # OSX
#         route = Command('route')
#         ifconfig = Command('ifconfig')
# 
#         iface = [
#             line.strip()
#             for line in route('-n', 'get', 'default')
#             if line.strip().startswith('interface')
#         ][0].split(':')[1].strip()
#         return [
#             line.strip()
#             for line in ifconfig(iface)
#             if line.strip().startswith('inet ')
#         ][0].split(' ')[1]
#     elif sys_name == 'Linux':
#         try:
#             ip = Command('ip')
#             iface = [
#                 line.strip()
#                 for line in ip('route')
#                 if line.strip().startswith('default ')
#             ][0].split(' ')[4]
#         except CommandNotFound:
#             route = Command('route')
#             iface = [
#                 line.strip()
#                 for line in route('-n')
#                 if line.startswith('0.0.0.0')
#             ][0].split(' ').pop()
# 
#         try:
#             # try with IP
#             ip = Command('ip')
#             return [
#                 line.strip()
#                 for line in ip('addr', 'show', iface)
#                 if line.strip().startswith('inet ')
#             ][0].split(' ')[1].split('/')[0]
#         except CommandNotFound:
#             pass
# 
#         # fallback to ifconfig
#         ifconfig = Command('ifconfig')
#         return [
#             line.strip()
#             for line in ifconfig(iface)
#             if line.strip().startswith('inet ')
#         ][0].split(' ')[1]
# 
#     return None
# 
# def quote(s):
#     """Return a shell-escaped version of the string *s*."""
#     if not s:
#         return "''"
#     if _find_unsafe(s) is None:
#         return s
# 
#     # use single quotes, and put single quotes into double quotes
#     # the string $'b is then quoted as '$'"'"'b'
#     return "'" + s.replace("'", "'\"'\"'") + "'"


# Path: aeriscloud/cli/aeris/build.py
import click
import os
import re
import subprocess32
import sys
from aeriscloud.cli.helpers import Command, standard_options, \
    error, fatal, info, success, bold
from aeriscloud.utils import local_ip, quote

              "-executeMethod {method} " \
              "-logFile ./build.log " \
              "-projectPath {current_dir}" \
        .format(unity_path=quote(unity_path),
                method=methods[platform],
                current_dir=quote(os.getcwd()))
    info("""The following command will be executed:
{0}.""".format(bold(command)))
    returncode = subprocess32.call(command, shell=True)
    if returncode != 0:
        error("An error occurred, please check the content "
              "of the {0} log file.".format(bold('build.log')))
        sys.exit(returncode)

    if platform == 'ios':
        os.chdir(os.path.join(os.getcwd(), 'Build', 'iPhone'))
        command = "xcodebuild -scheme Unity-iPhone archive " \
                  "-archivePath Unity-iPhone.xcarchive"
        info("""The following command will be executed:
{0}.""".format(bold(command)))
        subprocess32.check_call(command, shell=True)
        command = "xcodebuild -exportArchive " \
                  "-exportFormat ipa " \
                  "-archivePath \"Unity-iPhone.xcarchive\" " \
                  "-exportPath \"Unity-iPhone.ipa\" " \
                  "-exportProvisioningProfile \"wildcard_Development\""
        info("""The following command will be executed:
{0}.""".format(bold(command)))
        subprocess32.check_call(command, shell=True)


    success("""