summaryrefslogtreecommitdiff
path: root/alot/utils
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2017-01-25 09:47:27 -0800
committerDylan Baker <dylan@pnwbakers.com>2017-01-25 10:37:27 -0800
commit4ea6a8df3dcbcef3209f86df1f27366fbb20440c (patch)
tree5b7c237bd3c004681b405337b0897b9cecdec774 /alot/utils
parent228309c8de79f878a4c5db64d8908ea54360045c (diff)
utils/argparse.py: Various cleanups
Hide internal values from export and add a message to the TypeError raised by the if the argument isn't in _TRUISH or _FALSISH.
Diffstat (limited to 'alot/utils')
-rw-r--r--alot/utils/argparse.py21
1 files changed, 11 insertions, 10 deletions
diff --git a/alot/utils/argparse.py b/alot/utils/argparse.py
index 968e9097..4922c247 100644
--- a/alot/utils/argparse.py
+++ b/alot/utils/argparse.py
@@ -1,5 +1,6 @@
# encoding=utf-8
# Copyright (C) 2011-2012 Patrick Totzke <patricktotzke@gmail.com>
+# Copyright © 2017 Dylan Baker
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -19,28 +20,28 @@
from __future__ import absolute_import
import argparse
+import itertools
-TRUEISH = ['true', 'yes', 'on', '1', 't', 'y']
-FALSISH = ['false', 'no', 'off', '0', 'f', 'n']
+_TRUEISH = ['true', 'yes', 'on', '1', 't', 'y']
+_FALSISH = ['false', 'no', 'off', '0', 'f', 'n']
-def boolean(string):
+def _boolean(string):
string = string.lower()
- if string in FALSISH:
+ if string in _FALSISH:
return False
- elif string in TRUEISH:
+ elif string in _TRUEISH:
return True
else:
- raise ValueError()
+ raise ValueError('Option must be one of: {}'.format(
+ ', '.join(itertools.chain(iter(_TRUEISH), iter(_FALSISH)))))
class BooleanAction(argparse.Action):
- """
- argparse action that can be used to store boolean values
- """
+ """Argparse action that can be used to store boolean values."""
def __init__(self, *args, **kwargs):
- kwargs['type'] = boolean
+ kwargs['type'] = _boolean
kwargs['metavar'] = 'BOOL'
argparse.Action.__init__(self, *args, **kwargs)