summaryrefslogtreecommitdiff
path: root/src/args.py
blob: 33c6276136e56e55c33f8b0dcde0196c764d9367 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""
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
        from optparse import SUPPRESS_HELP as SUPPRESS
        parser = OptionParser()
        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")
        parser.add_option("-d", "--debug", dest="debug",
                            help="The file where debug will be written", metavar="DEBUG_FILE")
        parser.add_option("-v", "--version", dest="version",
                            help=SUPPRESS, metavar="VERSION", default="0.8.1")
        (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.1")
        options = parser.parse_args()
    return options