import click


def get_hostname(ctx=None):
    """ Get the current API Gateway Hostname or error if not found """
    ctx = ctx or click.get_current_context()
    config = ctx.obj['config']
    hostname = config.get('core.hostname', None)
    if hostname is None:
        msg = "No hostname configured. Run `cray config set core " + \
              "hostname={Cray API URL}`"
        raise click.UsageError(msg)
    return hostname