def boolean_flag(parser, name, default=False, help_msg=None):
    """
    Add a boolean flag to argparse parser.

    :param parser: (argparse.Parser) parser to add the flag to
    :param name: (str) --<name> will enable the flag, while --no-<name> will disable it
    :param default: (bool) default value of the flag
    :param help_msg: (str) help string for the flag
    """
    dest = name.replace('-', '_')
    parser.add_argument('--' + name, action='store_true', default=default,
        dest=dest, help=help_msg)
    parser.add_argument('--no-' + name, action='store_false', dest=dest)
