r"""
    Returns a value of an argument specified on the command line after some flag

    CommandLine:
        python -c "import utool; print([(type(x), x) for x in [utool.get_argval('--quest')]])" --quest="holy grail"
        python -c "import utool; print([(type(x), x) for x in [utool.get_argval('--quest')]])" --quest="42"
        python -c "import utool; print([(type(x), x) for x in [utool.get_argval('--quest')]])" --quest=42
        python -c "import utool; print([(type(x), x) for x in [utool.get_argval('--quest')]])" --quest 42
        python -c "import utool; print([(type(x), x) for x in [utool.get_argval('--quest', float)]])" --quest 42

    Example:
        >>> # DISABLE_DOCTEST
        >>> from utool.util_arg import *  # NOQA
        >>> import sys
        >>> sys.argv.extend(['--spam', 'eggs', '--quest=holy grail', '--ans=42'])
        >>> get_argval('--spam', type_=str, default=None)
        eggs
        >>> get_argval('--quest', type_=str, default=None)
        holy grail
        >>> get_argval('--ans', type_=int, default=None)
        42

def get_argval(argstr, type_=None, default=None):
    r"""
    Returns a value of an argument specified on the command line after some flag

    CommandLine:
        python -c "import utool; print([(type(x), x) for x in [utool.get_argval('--quest')]])" --quest="holy grail"
        python -c "import utool; print([(type(x), x) for x in [utool.get_argval('--quest')]])" --quest="42"
        python -c "import utool; print([(type(x), x) for x in [utool.get_argval('--quest')]])" --quest=42
        python -c "import utool; print([(type(x), x) for x in [utool.get_argval('--quest')]])" --quest 42
        python -c "import utool; print([(type(x), x) for x in [utool.get_argval('--quest', float)]])" --quest 42

    Example:
        >>> # DISABLE_DOCTEST
        >>> from utool.util_arg import *  # NOQA
        >>> import sys
        >>> sys.argv.extend(['--spam', 'eggs', '--quest=holy grail', '--ans=42'])
        >>> get_argval('--spam', type_=str, default=None)
        eggs
        >>> get_argval('--quest', type_=str, default=None)
        holy grail
        >>> get_argval('--ans', type_=int, default=None)
        42
    """
    arg_after = default
    if type_ is bool:
        arg_after = False if default is None else default
    try:
        # New for loop way (accounts for =)
        for argx, item in enumerate(sys.argv):
            if item == argstr:
                if argx < len(sys.argv):
                    if type_ is bool:
                        arg_after = True
                    else:
                        arg_after = _try_cast(sys.argv[argx + 1], type_)
            if item.startswith(argstr + '='):
                val_after = ''.join(item.split('=')[1:])
                arg_after = _try_cast(val_after, type_)
    except Exception:
        pass
    return arg_after