#!/usr/bin/python
#-*- coding: utf-8 -*-

from r2spec.R2spec import R2spec
from optparse import OptionParser

#################################################
### argument
# retrieve the arguments given and show the help when needed
def getArgument():
    ''' Handle the parameters'''
    parser = OptionParser(version="%prog 3.0.3")
    parser.add_option("-u", "--url", dest="url",
                  help="Url of the R library")
    parser.add_option("-s", "--source", dest="source",
                  help="The source file (tarball) of the R library")
    parser.add_option("-p", "--package", dest="package",
                  help="The name of the R library")
                  
    parser.add_option("--bioc", dest="bioc", default=False, action="store_true",
                  help="For Bioconductor libraries, will add the correct Source0 in the spec file")
    parser.add_option("--cran", dest="cran", default=False, action="store_true",
                  help="For libraries coming from the CRAN repository, will add the correct Source0 in the spec file")
    parser.add_option("--rforge", dest="rforge", default=False, action="store_true",
                  help="For libraries coming from the r-forge.net repository, will add the correct Source0 in the spec file")
    parser.add_option("--rproject", dest="rproject", default=False, action="store_true",
                  help="For libraries coming from the r-forge.r-project.org repository, will add the correct Source0 in the spec file")
                  
    parser.add_option("-c", "--copyFile", dest="copyFile", default=False, action="store_true",
                  help="Copy directly the file to the SOURCES folder without asking")
    parser.add_option("-n", "--name", dest="name",
                  help="Name of the packager that will be used in the spec file")
    parser.add_option("-e", "--email", dest="email",
                  help="Email of the packager that will be used in the spec file")
    parser.add_option("-f", "--force", dest="force", default=False, action="store_true",
                  help="Create the spec file even if a file of the same name exists already in the working directory")
    (options, args) = parser.parse_args()

    return (options.source, options.url, options.package, \
    options.bioc, options.cran, options.rforge, options.rproject, \
    options.copyFile, options.name, \
    options.email, options.force)
################################################


if __name__ == "__main__":
    # Retrieve the given arguments
    (source, url, package, bioc, cran, rforge, rproject, copyFile, name, email, force) = getArgument()
    R2spec().main(source, url, package, bioc, cran, rforge, rproject, copyFile, name, email, force)
