# Path: aeriscloud/cli/aeris/sync.py
# def sync(box, direction):
#     if not box.project.rsync_enabled():
#         return None
# 
#     if direction == 'down':
#         click.secho('Syncing files down from the box...',
#                     fg='cyan', bold=True)
#         if box.rsync_down():
#             click.secho('Sync down done!', fg='green', bold=True)
#         else:
#             click.secho('Sync down failed!', fg='red', bold=True)
#             return False
#     elif direction == 'up':
#         click.secho('Syncing files up to the box...',
#                     fg='cyan', bold=True)
#         if box.rsync_up():
#             click.secho('Sync up done!', fg='green', bold=True)
#         else:
#             click.secho('Sync up failed!', fg='red', bold=True)
#             return False
#     else:
#         click.secho('error: invalid direction %s' % direction,
#                     fg='red', bold=True)
#         return False
# 
#     return True
# 
# Path: aeriscloud/cli/helpers.py
# 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)
# 
# 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)


import click
import os
import signal
import sys
import time
from watchdog.observers import Observer
from watchdog.tricks import AutoRestartTrick
from aeriscloud.cli.aeris.sync import sync
from aeriscloud.cli.helpers import standard_options, Command
                              watch_config['directories'])

        if 'patterns' in watch_config:
            patterns = watch_config['patterns']

        if 'ignores' in watch_config:
            ignore_patterns = watch_config['ignores']

        if 'run' in watch_config:
            run = watch_config['run'].split(' ')

    if command:
        run = command

    handler = BoxCommandAutoRestart(box, run,
                                    patterns=patterns,
                                    ignore_patterns=ignore_patterns,
                                    stop_signal=signal.SIGTERM)

    click.echo("Watching for changes on files matching %s on directories:" %
               click.style(', '.join(patterns), bold=True))

    observer = Observer(timeout=0.4)
    for directory in directories:
        click.echo(' * %s' % directory)
        observer.schedule(handler, directory, recursive=True)

    return handler, observer



# Path: aeriscloud/cli/aeris/sync.py
# def sync(box, direction):
#     if not box.project.rsync_enabled():
#         return None
# 
#     if direction == 'down':
#         click.secho('Syncing files down from the box...',
#                     fg='cyan', bold=True)
#         if box.rsync_down():
#             click.secho('Sync down done!', fg='green', bold=True)
#         else:
#             click.secho('Sync down failed!', fg='red', bold=True)
#             return False
#     elif direction == 'up':
#         click.secho('Syncing files up to the box...',
#                     fg='cyan', bold=True)
#         if box.rsync_up():
#             click.secho('Sync up done!', fg='green', bold=True)
#         else:
#             click.secho('Sync up failed!', fg='red', bold=True)
#             return False
#     else:
#         click.secho('error: invalid direction %s' % direction,
#                     fg='red', bold=True)
#         return False
# 
#     return True
# 
# Path: aeriscloud/cli/helpers.py
# 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)
# 
# 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)


# Path: aeriscloud/cli/aeris/watch.py
import click
import os
import signal
import sys
import time
from watchdog.observers import Observer
from watchdog.tricks import AutoRestartTrick
from aeriscloud.cli.aeris.sync import sync
from aeriscloud.cli.helpers import standard_options, Command

                              watch_config['directories'])

        if 'patterns' in watch_config:
            patterns = watch_config['patterns']

        if 'ignores' in watch_config:
            ignore_patterns = watch_config['ignores']

        if 'run' in watch_config:
            run = watch_config['run'].split(' ')

    if command:
        run = command

    handler = BoxCommandAutoRestart(box, run,
                                    patterns=patterns,
                                    ignore_patterns=ignore_patterns,
                                    stop_signal=signal.SIGTERM)

    click.echo("Watching for changes on files matching %s on directories:" %
               click.style(', '.join(patterns), bold=True))

    observer = Observer(timeout=0.4)
    for directory in directories:
        click.echo(' * %s' % directory)
        observer.schedule(handler, directory, recursive=True)

    return handler, observer



@click.command(cls=Command)