def parse_global_arguments(unparsed_arguments, top_level_parser, subparsers):
    """
    Given a sequence of arguments, a top-level parser (containing subparsers), and a subparsers
    object as returned by argparse.ArgumentParser().add_subparsers(), parse and return any global
    arguments as a parsed argparse.Namespace instance.
    """
    remaining_arguments = list(unparsed_arguments)
    present_subparser_names = set()
    for subparser_name, subparser in subparsers.choices.items():
        if subparser_name not in remaining_arguments:
            continue
        present_subparser_names.add(subparser_name)
        unused_parsed, remaining_arguments = subparser.parse_known_args(
            remaining_arguments)
    if (not present_subparser_names and '--help' not in unparsed_arguments and
        '-h' not in unparsed_arguments):
        for subparser_name in ('prune', 'create', 'check'):
            subparser = subparsers.choices[subparser_name]
            unused_parsed, remaining_arguments = subparser.parse_known_args(
                remaining_arguments)
    for subparser_name in present_subparser_names:
        if subparser_name in remaining_arguments:
            remaining_arguments.remove(subparser_name)
    return top_level_parser.parse_args(remaining_arguments)
