#!/usr/bin/env python

""" Simple CLI for basic SyncWrite operations."""

from __future__ import print_function
from collections import defaultdict
import mc_bin_client
import sys

if len(sys.argv) < 7:
    print("Usage: {} <host[:port]> <user> <password> <bucket> <op> <key> [value]".format(sys.argv[0]), file = sys.stderr)
    sys.exit(1)

(host, port) = sys.argv[1].split(":")
if not port:
    port = 11210

client = mc_bin_client.MemcachedClient(host=host, port=port)
client.enable_xerror()
client.hello("set_durable")
client.sasl_auth_plain(user=sys.argv[2], password=sys.argv[3])
client.bucket_select(sys.argv[4])

op = sys.argv[5]
key = sys.argv[6]
if len(sys.argv) > 7:
    value = sys.argv[7]

if op == "get":
    print (client.get(key))
elif op == "set":
    print (client.set(key, 0, 0, value))
elif op == "setD":
    print (client.setDurable(key, 0, 0, value))
elif op == "add":
    print (client.add(key, 0, 0, value))
elif op == "addD":
    print (client.addDurable(key, 0, 0, value))
elif op == "replace":
    print (client.replace(key, 0, 0, value))
elif op == "replaceD":
    print (client.replaceDurable(key, 0, 0, value))
elif op == "delete":
    print (client.delete(key, 0, 0))
elif op == "deleteD":
    print (client.deleteDurable(key, 0, 0))
else:
    print("Unknown op '" + op + "'", file=sys.stderr)

Add basic CLI for SyncWrite requests
[SR] Add basic CLI for SyncWrite requests

Add sync_repl.py; a basic command-line interface to making Synchronous
Replication requests.

Example usage - to perform a set with durability requirements to key
'test' setting its value to 'XXX':

    ./sync_repl.py localhost:12000 Administrator asdasd default setD test XXX

Change-Id: Ie54fdc8151b11e53bbbe360b0363790a9cdd5889
Reviewed-on: http://review.couchbase.org/103444
Reviewed-by: Trond Norbye <60edd2ef23891a753f231b0c6f161dc634079a93@gmail.com>
Reviewed-by: Paolo Cocchi <9dd88c9f3e5cbab6e19a6c020f107e0c648ac956@couchbase.com>
Tested-by: Dave Rigby <a09264da4832c7ff1d3bf1608a19f4b870f93750@couchbase.com>
