2012-08-06 13:01:39 +00:00
|
|
|
"""
|
|
|
|
Module related to the argument parsing
|
|
|
|
|
|
|
|
There is a fallback to the deprecated optparse if argparse is not found
|
|
|
|
"""
|
|
|
|
from os import path
|
|
|
|
|
|
|
|
def parse_args(CONFIG_PATH=''):
|
|
|
|
"""
|
|
|
|
Parse the arguments from the command line
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
from argparse import ArgumentParser, SUPPRESS
|
|
|
|
except ImportError:
|
|
|
|
from optparse import OptionParser
|
2012-08-06 13:07:38 +00:00
|
|
|
from optparse import SUPPRESS_HELP as SUPPRESS
|
2012-08-06 13:01:39 +00:00
|
|
|
parser = OptionParser()
|
|
|
|
parser.add_option("-f", "--file", dest="filename", default=path.join(CONFIG_PATH, 'poezio.cfg'),
|
2012-08-06 13:07:38 +00:00
|
|
|
help="The config file you want to use", metavar="CONFIG_FILE")
|
2012-08-06 13:01:39 +00:00
|
|
|
parser.add_option("-d", "--debug", dest="debug",
|
2012-08-06 13:07:38 +00:00
|
|
|
help="The file where debug will be written", metavar="DEBUG_FILE")
|
2012-08-06 13:01:39 +00:00
|
|
|
parser.add_option("-v", "--version", dest="version",
|
2012-08-06 13:07:38 +00:00
|
|
|
help=SUPPRESS, metavar="VERSION", default="0.8-dev")
|
2012-08-06 13:01:39 +00:00
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
else:
|
|
|
|
parser = ArgumentParser()
|
|
|
|
parser.add_argument("-f", "--file", dest="filename", default=path.join(CONFIG_PATH, 'poezio.cfg'),
|
|
|
|
help="The config file you want to use", metavar="CONFIG_FILE")
|
|
|
|
parser.add_argument("-d", "--debug", dest="debug",
|
|
|
|
help="The file where debug will be written", metavar="DEBUG_FILE")
|
|
|
|
parser.add_argument("-v", "--version", dest="version",
|
|
|
|
help=SUPPRESS, metavar="VERSION", default="0.8-dev")
|
|
|
|
options = parser.parse_args()
|
|
|
|
return options
|