summaryrefslogtreecommitdiff
path: root/src/args.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2012-08-06 15:01:39 +0200
committermathieui <mathieui@mathieui.net>2012-08-06 15:01:39 +0200
commit100994df284e1ce004e8babaeece128b1bd92479 (patch)
treeb2b58fe37424908053d8d7faac80b2b3115d7e34 /src/args.py
parent5692a0278be231070a44d53aabb5daccad2a1ad6 (diff)
downloadpoezio-100994df284e1ce004e8babaeece128b1bd92479.tar.gz
poezio-100994df284e1ce004e8babaeece128b1bd92479.tar.bz2
poezio-100994df284e1ce004e8babaeece128b1bd92479.tar.xz
poezio-100994df284e1ce004e8babaeece128b1bd92479.zip
Add a fallback to optparse if argparse is not found
Diffstat (limited to 'src/args.py')
-rw-r--r--src/args.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/args.py b/src/args.py
new file mode 100644
index 00000000..b0334fcc
--- /dev/null
+++ b/src/args.py
@@ -0,0 +1,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_USAGE as SUPPRESS
+ parser = OptionParser()
+ parser.add_option("-f", "--file", dest="filename", default=path.join(CONFIG_PATH, 'poezio.cfg'),
+ usage="The config file you want to use", metavar="CONFIG_FILE")
+ parser.add_option("-d", "--debug", dest="debug",
+ usage="The file where debug will be written", metavar="DEBUG_FILE")
+ parser.add_option("-v", "--version", dest="version",
+ usage=SUPPRESS, metavar="VERSION", default="0.8-dev")
+ (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