Create a Python script that connects to a Cassandra database and performs basic CRUD operations (Create, Read, Update, Delete) on a table containing user information (name, email, age). The script should support command line arguments for specifying the connection details (host, port, keyspace).
PLAINFORMAT
import argparse
from cassandra.cluster import Cluster
from cassandra.query import SimpleStatement

def create_table(session):
    session.execute("""
        CREATE TABLE IF NOT EXISTS users (
            name text PRIMARY KEY,
            email text,
            age int
        )
    """)

def insert_user(session, name, email, age):
    query = "INSERT INTO users (name, email, age) VALUES (%s, %s, %s)"
    session.execute(query, (name, email, age))

def update_user(session, name, email=None, age=None):
    if email:
        query = "UPDATE users SET email=%s WHERE name=%s"
        session.execute(query, (email, name))
    
    if age:
        query = "UPDATE users SET age=%s WHERE name=%s"
        session.execute(query, (age, name))

def delete_user(session, name):
    query = "DELETE FROM users WHERE name=%s"
    session.execute(query, (name,))

def get_users(session):
    result = session.execute("SELECT * FROM users")
    return result.all()

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Cassandra CRUD operations")
    parser.add_argument("--host", required=True, help="Cassandra host")
    parser.add_argument("--port", type=int, default=9042, help="Cassandra port")
    parser.add_argument("--keyspace", required=True, help="Cassandra keyspace")

    args = parser.parse_args()

    cluster = Cluster([args.host], port=args.port)
    session = cluster.connect(args.keyspace)

    # Create table
    create_table(session)

    # Insert user
    insert_user(session, "John Doe", "john.doe@example.com", 30)

    # Update user
    update_user(session, "John Doe", email="john.new_email@example.com")

    # Get users
    users = get_users(session)
    print("Users:")
    for user in users:
        print(user)

    # Delete user
    delete_user(session, "John Doe")

    cluster.shutdown()