Exemplo n.º 1
0
def _do_wrap(context, method, path, options, config, h, q, data=None):
    conf = utils.load_conf(config)
    current = current_host(conf)
    if current is None:
        click.echo("No current host set")
        exit(1)
    code = req.handle_request(method, path, conf[glob.HOSTS][current], options, h,
                              q, data=data)
    if code >= 400:
        exit(1)
    exit(0)
Exemplo n.º 2
0
def main_run(context, command, arguments, config):
    commands = ['add', 'remove', 'set', 'list', 'change']
    cmd_arg_list = list(arguments)
    conf = utils.load_conf(config, glob.HOSTS, glob.CONF)
    if command is None:
        current = current_host(conf)
        if current is None:
            click.echo("No current host set")
        else:
            click.echo("%s:%s" % (current, conf[glob.HOSTS][current]))
            exit(0)
    if command in commands:
        if command == 'list':
            for host in conf[glob.HOSTS]:
                click.echo("%s:%s" % (host, conf[glob.HOSTS][host]))
            exit(0)
        if command == 'change':
            host = cmd_arg_list.pop(0)
            info = " ".join(cmd_arg_list)
            if not utils.validate_host(info):
                click.echo("Invalid host setting.")
                exit(1)
            if host not in conf[glob.HOSTS]:
                click.echo("Host '%s' not defined" % host)
                exit(1)
            conf[glob.HOSTS][host] = info
            conf.write()
            exit(0)
        if command == 'add':
            host = cmd_arg_list.pop(0)
            info = " ".join(cmd_arg_list)
            if not utils.validate_host(info):
                click.echo("Invalid host setting.")
                exit(1)
            if host in conf[glob.HOSTS]:
                click.echo("Host '%s' already defined" % host)
                exit(1)
            conf[glob.HOSTS][host] = info
            conf.write()
            exit(0)
        if command == 'remove':
            host = cmd_arg_list.pop(0)
            if host not in conf[glob.HOSTS]:
                click.echo("Host '%s' not configured" % host)
                exit(1)
            del conf[glob.HOSTS][host]
            conf.write()
            exit(0)
    else:
        if command not in conf[glob.HOSTS]:
            click.echo("Host '%s' not configured" % command)
            exit(1)
        conf[glob.CONF]['current'] = command
        conf.write()