Runs the function if the module in which it is declared is being run
        directly from the commandline. Putting the following after the function
        definition would be similar:

        if __name__ == '__main__':
            func()

        NOTE: This will work most expectedly as the outermost decorator, as it
        will call the function before any more outwards decorators have been
        applied.

def autorun(func, _depth=1):
    """
        Runs the function if the module in which it is declared is being run
        directly from the commandline. Putting the following after the function
        definition would be similar:

        if __name__ == '__main__':
            func()

        NOTE: This will work most expectedly as the outermost decorator, as it
        will call the function before any more outwards decorators have been
        applied.
    """

    frame_local = sys._getframe(_depth).f_locals
    if '__name__' in frame_local and frame_local['__name__'] == '__main__':
        func(argv=sys.argv[1:])

    return func