docs: def main(self, argv=None, loop=LOOP_NEVER):
          """A possible mainline handler for a script, like so:
  
              import cmdln
              class MyCmd(cmdln.Cmdln):
                  name = "mycmd"
                  ...
  
              if __name__ == "__main__":
                  MyCmd().main()
  
          By default this will use sys.argv to issue a single command to
          'MyCmd', then exit. The 'loop' argument can be use to control
          interactive shell behaviour.
  
          Arguments:
              "argv" (optional, default sys.argv) is the command to run.
                  It must be a sequence, where the first element is the
                  command name and subsequent elements the args for that
                  command.
              "loop" (optional, default LOOP_NEVER) is a constant
                  indicating if a command loop should be started (i.e. an
                  interactive shell). Valid values (constants on this module):
                      LOOP_ALWAYS     start loop and run "argv", if any
                      LOOP_NEVER      run "argv" (or .emptyline()) and exit
                      LOOP_IF_EMPTY   run "argv", if given, and exit;
                                      otherwise, start loop
          """
          if argv is None:
              import sys
              argv = sys.argv
          else:
              argv = argv[:]  # don't modify caller's list
  
          self.optparser = self.get_optparser()
          if self.optparser:  # i.e. optparser=None means don't process for opts
              try:
                  self.options, args = self.optparser.parse_args(argv[1:])
              except CmdlnUserError as ex:
                  msg = "%s: %s\nTry '%s help' for info.\n" % (self.name, ex,
                                                               self.name)
                  self.stderr.write(self._str(msg))
                  self.stderr.flush()
                  return 1
              except StopOptionProcessing as ex:
                  return 0
          else:
              self.options, args = None, argv[1:]
  
          retval = self.postoptparse()
          if retval:
              return retval
  
          if loop == LOOP_ALWAYS:
              if args:
                  self.cmdqueue.append(args)
              return self.cmdloop()
          elif loop == LOOP_NEVER:
              if args:
                  return self.cmd(args)
              else:
                  return self.emptyline()
          elif loop == LOOP_IF_EMPTY:
              if args:
                  return self.cmd(args)
              else:
                  return self.cmdloop()