def get_optarg(arglist, *opts, default=False):
    """Gets an optional command line argument and returns its value.

    If default is not set, the flag is treated as boolean. Note that
    that setting default to None or '' will still take an argument
    after the flag.

    Parameters
    ----------
    arglist : array_like
        The command line argument list to be parsed.
    opts : list
        The arguments searched for in arglist.
    default : str or bool
        The default value if opts are not found in arglist. If default
        is False (default), then True is returned if opts are found.

    Returns
    -------
    str or bool
        The argument value in arglist or its default value.
    """
    for op in opts:
        if op in arglist:
            ind = arglist.index(op)
            arglist.remove(op)
            if default is False:
                return True
            else:
                return arglist.pop(ind)

    return default