from os.path import abspath, dirname, join

import halsim_gui
import inspect
import logging

logger = logging.getLogger("pyfrc.sim")


class PyFrcSim:
    """
    Runs the robot using WPILib's GUI HAL Simulator
    """

    def __init__(self, parser):
        pass

    def run(self, options, robot_class, **static_options):
        halsim_gui.loadExtension()

        # initialize physics, attach to the user robot class
        from ..physics.core import PhysicsInterface, PhysicsInitException

        robot_file = abspath(inspect.getfile(robot_class))
        robot_path = dirname(robot_file)

        try:
            physics = PhysicsInterface._create(robot_path)
            if physics:
                robot_class._simulationInit = physics._simulationInit
                robot_class._simulationPeriodic = physics._simulationPeriodic

            # run the robot
            return robot_class.main(robot_class)

        except PhysicsInitException:
            return False

@@ -33,23 +33,16 @@
 name
-, join%0A
 %0Aimport 
 hals
@@ -37,26 +37,24 @@
 %0Aimport 
-halsim_gui
+argparse
 %0Aimport 
@@ -237,84 +237,486 @@
 rser
-):%0A        pass%0A%0A    def run(self, options, robot_class, **static_options):%0A
+: argparse.ArgumentParser):%0A        parser.add_argument(%0A            %22--gui%22,%0A            default=False,%0A            action=%22store_true%22,%0A            help=%22Use the WPIlib simulation gui%22,%0A        )%0A%0A    def run(self, options, robot_class, **static_options):%0A%0A        if options.gui:%0A            try:%0A                import halsim_gui%0A            except ImportError:%0A                print(%22robotpy-halsim-gui is not installed!%22)%0A                exit(1)%0A            else:%0A        
     

move simgui to flag