def choose_token_getter(getters):
    """Ask the user to choose a token getter amongst those available."""
    if len(getters) == 1:
        _label, getter = getters[0]
        return getter
    print("cogite needs a personal access token. There are several ways to get one:")
    for idx, (label, _) in enumerate(getters, start=1):
        print(f"{idx}. {label}")
    choices = range(1, len(getters) + 1)
    while 1:
        choices_help = ', '.join(str(i) for i in range(1, len(getters)))
        choices_help += f' or {len(getters)}'
        choice = input(
            f"Please choose one of the methods above by typing {choices_help}: "
        )
        try:
            choice = int(choice)
        except ValueError:
            pass
        else:
            if choice in choices:
                _label, getter = getters[choice - 1]
                return getter
        print("Wrong choice. Try again.")