import getpass


def ensure_token(token=None):
    """Requests for token if token is not already available."""
    if token is None:
        print("    - Create a token with full 'repo' permissions at "
              "https://github.com/settings/tokens\n"
              "    - Save or write it down somewhere \n"
              "    - Type it in the prompt above\n\n"
              "'Repository not found' means you didn't give the token"
              " full 'repo' permissions.\n"
              "'Authentication failed' means you mistyped the token.\n")
        # We could prompt for username/password instead, but then the password
        # would be printed in plaintext if there is any problem during cloning.
        token = getpass.getpass('Github OAuth token: ')
    return token