args.py 1.8 KB
Newer Older
1 2 3 4 5
"""
Module related to the argument parsing

There is a fallback to the deprecated optparse if argparse is not found
"""
6
from gettext import gettext as _
7 8 9 10 11 12 13 14 15 16
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
mathieui's avatar
mathieui committed
17
        from optparse import SUPPRESS_HELP as SUPPRESS
18
        parser = OptionParser()
19 20 21 22
        parser.add_option("-f", "--file", dest="filename",
                          default=path.join(CONFIG_PATH, 'poezio.cfg'),
                          help=_("The config file you want to use"),
                          metavar="CONFIG_FILE")
23
        parser.add_option("-d", "--debug", dest="debug",
24 25
                          help=_("The file where debug will be written"),
                          metavar="DEBUG_FILE")
26
        parser.add_option("-v", "--version", dest="version",
27 28 29
                          help=SUPPRESS, metavar="VERSION",
                          default="0.8.3-dev")
        (options, __) = parser.parse_args()
30 31
    else:
        parser = ArgumentParser()
32 33 34 35
        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")
36
        parser.add_argument("-d", "--debug", dest="debug",
37 38
                            help=_("The file where debug will be written"),
                            metavar="DEBUG_FILE")
39
        parser.add_argument("-v", "--version", dest="version",
40 41
                            help=SUPPRESS, metavar="VERSION",
                            default="0.8.3-dev")
42 43
        options = parser.parse_args()
    return options