#!/usr/bin/env python

import argparse

from common.docker_helpers import (check_root, create_volumes, start_container,
                                   connect_to_container, stop_container,
                                   restore_file_ownership)


def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument('-t', '--tag', help='Docker image tag to run. Default'
                                            ' is latest, try develop to get'
                                            ' the latest w3af features.',
                        required=False)
    args = parser.parse_args()
    return args


if __name__ == '__main__':
    check_root()

    args = parse_args()

    create_volumes()
    container_id = start_container(args.tag)

    cmd = '/home/w3af/w3af/w3af_gui --no-update'
    extra_ssh_flags = ('-X',)
    try:
        connect_to_container(container_id, cmd)
    finally:
        stop_container(container_id)
        restore_file_ownership()
