#!/usr/bin/env python3

from cli_auth_utils import get_authed_clitool, cmd_decorator


@cmd_decorator
def listvb(mc):
    vbs = mc.stats('vbucket')
    for (vb, state) in sorted(list(vbs.items())):
        print("vbucket", vb[3:], state)


@cmd_decorator
def setvb(mc, vbid, vbstate):
    mc.set_vbucket_state(int(vbid), vbstate)


@cmd_decorator
def rmvb(mc, vbid):
    mc.delete_vbucket(int(vbid))


if __name__ == '__main__':
    c = get_authed_clitool(allBuckets=False)

    c.addCommand('list', listvb, 'list')
    c.addCommand('set', setvb, 'set <vbid> active|replica|pending|dead')
    c.addCommand('rm', rmvb, 'rm <vbid>')

    c.execute()
