def main(command_class=None, args=None):
<EOL>if '<STR_LIT>' in os.environ:<EOL><INDENT>level = getattr(logging, os.environ['<STR_LIT>'].upper(), None)<EOL>if level is not None:<EOL><INDENT>logging.basicConfig(level=level)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>logging.basicConfig(level=logging.INFO)<EOL>base_logger = logging.getLogger('<STR_LIT>')<EOL>if len(base_logger.handlers) == <NUM_LIT:0>:<EOL><INDENT>handler = logging.StreamHandler()<EOL>handler.setFormatter(<EOL>logging.Formatter(u'<STR_LIT>'))<EOL>base_logger.addHandler(handler)<EOL>base_logger.propagate = False<EOL><DEDENT><DEDENT>title = '<STR_LIT>'<EOL>if command_class is not None:<EOL><INDENT>title, _, _ = command_class.__doc__.partition('<STR_LIT>')<EOL><DEDENT>parser = argparse.ArgumentParser(description=title)<EOL>parser.add_argument('<STR_LIT>', metavar='<STR_LIT:file>', default='<STR_LIT:.>',<EOL>help='<STR_LIT>')<EOL>parser.add_argument(<EOL>'<STR_LIT>', '<STR_LIT>', action='<STR_LIT:version>',<EOL>version='<STR_LIT>' + package_version)<EOL>if command_class is not None:<EOL><INDENT>command_class.init_parser(parser)<EOL>parser.set_defaults(command=command_class)<EOL><DEDENT>else:<EOL><INDENT>commands = {}<EOL>for entry in pkg_resources.iter_entry_points('<STR_LIT>'):<EOL><INDENT>canonical = entry.name.lower()<EOL>if canonical not in commands:<EOL><INDENT>command_class = entry.load()<EOL>commands[canonical] = command_class<EOL><DEDENT>else:<EOL><INDENT>logger.warning('<STR_LIT>'.format(<EOL>canonical))<EOL><DEDENT><DEDENT>subparsers = parser.add_subparsers(title='<STR_LIT>', metavar='<STR_LIT>')<EOL>for name, command_class in sorted(iteritems(commands)):<EOL><INDENT>title, _, _ = command_class.__doc__.partition('<STR_LIT>')<EOL>subparser = subparsers.add_parser(<EOL>name, help=title.rstrip('<STR_LIT:.>'),<EOL>formatter_class=argparse.RawDescriptionHelpFormatter,<EOL>description=_trim(command_class.__doc__))<EOL>subparser.set_defaults(command=command_class)<EOL>command_class.init_parser(subparser)<EOL><DEDENT><DEDENT>parsed_args = parser.parse_args(args)<EOL>model = native.ModelReader.reader_from_path(<EOL>parsed_args.model).create_model()<EOL>command = parsed_args.command(model, parsed_args)<EOL>try:<EOL><INDENT>command.run()<EOL><DEDENT>except CommandError as e:<EOL><INDENT>parser.error(text_type(e))<EOL><DEDENT>
Run the command line interface with the given :class:`Command`.

    If no command class is specified the user will be able to select a specific
    command through the first command line argument. If the ``args`` are
    provided, these should be a list of strings that will be used instead of
    ``sys.argv[1:]``. This is mostly useful for testing.