import argparse
import os
import subprocess

# Delete the specified project from the specified hub
def del_project(hubaddr, project_id):
    curl_cmd = ['curl']

    delete_args = ['-L', 
                   '--cookie-jar','cookies.txt',
                   '-d', f'remove_project_id={project_id}',
                   hubaddr]
    subprocess.check_call(curl_cmd + delete_args)


# Set up.
def go():
    parser = argparse.ArgumentParser(
        description=('Delete a project from a CodeSonar hub,'
                     + 'as specified by the command-line arguments.'))
        
    parser.add_argument("hub",
                        help="The hub URL.")
    parser.add_argument("pid",
                        help="The project ID for the project to delete.")
    args = parser.parse_args()

    allargs = (args.hub, args.pid)
    if not any([a is None for a in allargs]):
        del_project(*allargs)

go()
