aboutsummaryrefslogtreecommitdiffstats
path: root/auto-auto-complete.py
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2013-08-17 11:09:31 +0200
committerMattias Andrée <maandree@operamail.com>2013-08-17 11:09:31 +0200
commit77719279981eff89fd2e052789e9077b5614b516 (patch)
tree919f3ea94bcc54adc9d824655cee553eadbbd5aa /auto-auto-complete.py
parentkeep track of line, column and character (diff)
downloadauto-auto-complete-77719279981eff89fd2e052789e9077b5614b516.tar.gz
auto-auto-complete-77719279981eff89fd2e052789e9077b5614b516.tar.bz2
auto-auto-complete-77719279981eff89fd2e052789e9077b5614b516.tar.xz
cleaner fail
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'auto-auto-complete.py')
-rwxr-xr-xauto-auto-complete.py23
1 files changed, 17 insertions, 6 deletions
diff --git a/auto-auto-complete.py b/auto-auto-complete.py
index 8fb7710..9783804 100755
--- a/auto-auto-complete.py
+++ b/auto-auto-complete.py
@@ -41,6 +41,17 @@ def printerr(text = '', end = '\n'):
sys.stderr.buffer.write((str(text) + end).encode('utf-8'))
+'''
+Abort the program
+
+@param text:str Error message
+@return returncode:int The programs return code
+'''
+def abort(text, returncode = 1):
+ printerr('\033[01;31m%s\033[00m' % text)
+ sys.exit(returnvalue)
+
+
'''
@@ -132,7 +143,7 @@ class Parser:
col = 0
char = 0
- raise Exception('premature end of file')
+ abort('premature end of file')
'''
@@ -761,7 +772,7 @@ mane!
if __name__ == '__main__':
if len(sys.argv) != 6:
print("USAGE: auto-auto-complete SHELL --output OUTPUT_FILE --source SOURCE_FILE")
- exit(1)
+ exit(2)
shell = sys.argv[1]
output = None
@@ -779,9 +790,9 @@ if __name__ == '__main__':
if option == '--output': old = output; output = arg
elif option == '--source': old = source; source = arg
else:
- raise Exception('Unrecognised option: ' + option)
+ abort('Unrecognised option: ' + option)
if old is not None:
- raise Exception('Duplicate option: ' + option)
+ abort('Duplicate option: ' + option)
for arg in sys.argv[2:]:
if option is not None:
@@ -795,8 +806,8 @@ if __name__ == '__main__':
else:
option = arg
- if output is None: raise Exception('Unused option: --output')
- if source is None: raise Exception('Unused option: --source')
+ if output is None: abort('Unused option: --output')
+ if source is None: abort('Unused option: --source')
main(shell= shell, output= output, source= source)