'Receive real time events from containers.
Usage: events [options] [SERVICE...]
Options:
--json      Output events as a stream of json objects'

def events(self, options):

    def format_event(event):
        attributes = [(u'%s=%s' % item) for item in event[u'attributes'].items()]
        return u'{time}    {type}    {action}    {id}    ({attrs})'.format(attrs=u',    '.join(sorted(attributes)), **event)
    def json_format_event(event):
        event[u'time'] = event[u'time'].isoformat()
        event.pop(u'container')
        return json.dumps(event)
    for event in self.project.events():
        formatter = (json_format_event if options[u'--json'] else format_event)
        print(formatter(event))
        sys.stdout.flush()
