From cceec453ae54b19606a7e4ad743ff13f750e57f8 Mon Sep 17 00:00:00 2001 From: Patrick Totzke Date: Sun, 5 Nov 2017 16:59:43 +0000 Subject: sanitize parameter for thread mode command 'indent' this introduces a new argparse validation check that makes sure a parameter is '+', '-', or an integer, and uses this check for the 'indent' thread mode command. --- alot/utils/argparse.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'alot/utils') diff --git a/alot/utils/argparse.py b/alot/utils/argparse.py index adacdd6e..ff19030c 100644 --- a/alot/utils/argparse.py +++ b/alot/utils/argparse.py @@ -97,6 +97,16 @@ def require_dir(path): raise ValidationFailed('{} is not a valid directory.'.format(path)) +def is_int_or_pm(value): + """Validator to assert that value is '+', '-', or an integer""" + if value not in ['+', '-']: + try: + value = int(value) + except ValueError: + raise ValidationFailed('value must be an integer or "+" or "-".') + return value + + class BooleanAction(argparse.Action): """Argparse action that can be used to store boolean values.""" def __init__(self, *args, **kwargs): -- cgit v1.2.3