def main(args=None):
    """Main command-line interface entrypoint.

    Runs the given subcommand or argument that were specified.  If not given a
    ``args`` parameter, assumes the arguments are passed on the command-line.

    Args:
      args (list): list of command-line arguments

    Returns:
      Zero on success, non-zero otherwise.
    """
    if args is None:
        args = sys.argv[1:]

    parser = create_parser()
    args = parser.parse_args(args)

    if args.verbose >= 2:
        level = logging.DEBUG
    elif args.verbose >= 1:
        level = logging.INFO
    else:
        level = logging.WARNING

    logging.basicConfig(level=level)

    try:
        args.command(args)
    except pylink.JLinkException as e:
        sys.stderr.write('Error: %s%s' % (str(e), os.linesep))
        return 1

    return 0