code: def entrypoint(func):
      
      frame_local = sys._getframe(1).f_locals
      if '__name__' in frame_local and frame_local['__name__'] == '__main__':
          argv = sys.argv[1:]
  
          parser = signature_parser(func)
          try:
              kwargs = parser.parse_args(argv).__dict__
  
              # special cli flags
  
              # --version is handled by ArgParse
              # if kwargs.get('version'):
              #    print module_version(func)
              #    return
              if 'version' in kwargs.keys():
                  del kwargs['version']
  
              # --debug
              FORMAT = '%(asctime)-6s: %(name)s - %(levelname)s - %(message)s'
              if kwargs.get('debug'):
                  logging.basicConfig(
                      level=logging.DEBUG,
                      format=FORMAT,
                  )
              del kwargs['debug']
  
              if "__args" in kwargs:
                  return func(*_correct_args(func, kwargs))
              else:
                  return func(**kwargs)
  
          except UsageError, e:
              parser.error(e.message)
  
      return func
docs: A decorator for your main() function.
  
          Really a combination of @autorun and @acceptargv, so will run the
          function if __name__ == '__main__' with arguments extricated from
          argparse.
  
          As with @acceptargv, this must either be the innermost decorator, or
          separated only by "well-behaved" decorators that preserve the __doc__
          attribute AND the function signature.
  
          As with @autorun, this must be theoutermost decorator, as any
          decorators further out will not be applied to the function until after
          it is run.