def get_next_arg(desc, args):
    """
    Get either the value matching key 'desc.name' or the next arg in
    the non-dict list.  Return None if args are exhausted.  Used in
    validate() below.
    """
    arg = None
    if isinstance(args, dict):
        arg = args.pop(desc.name, None)
        if arg == '':
            arg = desc.name
        if arg and isinstance(arg, list):
            args[desc.name] = arg[1:]
            arg = arg[0]
    elif args:
        arg = args.pop(0)
        if arg and isinstance(arg, list):
            args = arg[1:] + args
            arg = arg[0]
    return arg
