

def main():
    usage = 'usage: %prog <init|zip|register|publish> [options]'
    p = optparse.OptionParser(usage=usage)
    p.add_option('--out', '-o', type='string', default='.', help='The output directory for the package')
    p.add_option('--name', '-n', type='string', help=('The name of the package. ' + name_template))
    p.add_option('--version', '-v', type='string', help=('The version of the release, when using ' + 'zip or publish.'))
    p.add_option('--folder', '-f', type='string', help='The root folder of the package that will be prepped for release')
    init_options = optparse.OptionGroup(p, "'init' specific options", 'Use these options when you want to set up an empty project with the standard template. You must supply a name when using init.')
    init_options.add_option('--scala', '-s', action='store_true', default=False, help='Include this if your package uses/will use scala code. If none of the language flags are used, the package will be created using the scala template by default.')
    init_options.add_option('--java', '-j', action='store_true', default=False, help='Include this if your package uses/will use java code')
    init_options.add_option('--python', '-p', action='store_true', default=False, help='Include this if your package has/will have python code')
    init_options.add_option('--R', '-r', action='store_true', default=False, dest='r', help='Include this if your package has/will have R code')
    p.add_option_group(init_options)
    credentials_options = optparse.OptionGroup(p, 'credentials', (('Set these options when you want to register your package or publish a release on ' + 'Spark Packages. If credentials are not supplied beforehand, you will be prompted to ') + 'enter them.'))
    credentials_options.add_option('--user', '-u', type='string', help='Your github username. It is safer to provide this through a file using -c or --cred.')
    credentials_options.add_option('--token', '-t', type='string', help=('Your github personal access token with read:org authorization. It ' + 'is safer to provide this through a file using -c or --cred.'))
    credentials_options.add_option('--cred', '-c', type='string', help='A file containing your github credentials, i.e. your username and personal access token with read:org authorization. The format should be:\nuser= $USERNAME\npassword= $TOKEN')
    p.add_option_group(credentials_options)
    register_options = optparse.OptionGroup(p, 'register', (('Register your package on Spark Packages. Requires that your package exist as a Github ' + 'repository. If credentials are not supplied through command line arguments, you will be ') + 'asked to enter them. Example usage: spark-package register -n $PACKAGE_NAME -c $CREDS_FILE.'))
    p.add_option_group(register_options)
    publish_options = optparse.OptionGroup(p, "'publish' specific options", ('Set these options when you want to publish a release on Spark Packages. Example ' + 'usage: spark-package publish -c $CREDS_FILE -n $PACKAGE_NAME -f $PACKAGE_PATH -v $VERSION'))
    publish_options.add_option('--zip', '-z', type='string', help='The zip file containing the release artifact, if it has been generated beforehand.')
    p.add_option_group(publish_options)
    (options, arguments) = p.parse_args()
    if (len(arguments) == 0):
        show_error_and_exit(("Please specify an action, such as 'init', 'zip', 'register' or " + "'publish'"), p)
    if (len(arguments) > 1):
        show_error_and_exit('Unrecognized arguments', p)
    validate_name(options.name, p)
    if (arguments[0] == 'init'):
        if ((not options.scala) and (not options.java) and (not options.python) and (not options.r)):
            options.scala = True
        init_empty_package(options.out, options.name, options.scala, options.java, options.python, options.r)
    elif (arguments[0] == 'zip'):
        if (not check_path_exists(options.folder)):
            show_error_and_exit('Please specify the folder of the spark package', p)
        if ((options.version is None) or (len(options.version.strip()) == 0)):
            show_error_and_exit('Please specify a version for the release', p)
        zip_artifact(options.folder, options.name, options.version, options.out)
    elif (arguments[0] == 'register'):
        (user, token) = resolve_credentials(options.user, options.token, options.cred)
        register_package(options.name, user, token)
    elif (arguments[0] == 'publish'):
        (user, token) = resolve_credentials(options.user, options.token, options.cred)
        if ((not check_path_exists(options.folder)) and (not check_path_exists(options.zip))):
            show_error_and_exit(('Please specify the folder of the spark package or the path ' + 'to the zip file.'), p)
        if ((options.version is None) or (len(options.version.strip()) == 0)):
            show_error_and_exit('Please specify a version for the release', p)
        publish_release(options.name, user, token, options.folder, options.version, options.out, options.zip)
    else:
        show_error_and_exit(('Unrecognized argument %s' % arguments[0]))

dataset/ETHPy150Open databricks/spark-package-cmd-tool/python/spark_package/spark_package.py main/original