# Path: alertaclient/auth/utils.py
# def clear_token(endpoint):
#     try:
#         info = netrc(NETRC_FILE)
#     except Exception as e:
#         raise ConfigurationError(f'{e}')
#     try:
#         del info.hosts[machine(endpoint)]
#         with open(NETRC_FILE, 'w') as f:
#             f.write(dump_netrc(info))
#     except KeyError as e:
#         raise ConfigurationError(f'No credentials stored for {e}')


import click
from alertaclient.auth.utils import clear_token



@click.command('logout', short_help='Clear login credentials')
@click.pass_obj
def cli(obj):
    """Clear local login credentials from netrc file."""
    client = obj['client']

# Path: alertaclient/auth/utils.py
# def clear_token(endpoint):
#     try:
#         info = netrc(NETRC_FILE)
#     except Exception as e:
#         raise ConfigurationError(f'{e}')
#     try:
#         del info.hosts[machine(endpoint)]
#         with open(NETRC_FILE, 'w') as f:
#             f.write(dump_netrc(info))
#     except KeyError as e:
#         raise ConfigurationError(f'No credentials stored for {e}')


# Path: alertaclient/commands/cmd_logout.py
import click
from alertaclient.auth.utils import clear_token




@click.command('logout', short_help='Clear login credentials')
@click.pass_obj
def cli(obj):
    """Clear local login credentials from netrc file."""
    client = obj['client']

    clear_token(client.endpoint)